javascript - Phone number regex validation - Stack Overflow

Need to validate phone numbers which are separated by ma and it can have country code as start paramete

Need to validate phone numbers which are separated by ma and it can have country code as start parameter. I need to do temporary validation in front end side such as validating different numbers

  1. number with country code(min length and max length should be specified): +919845098450
  2. number without country code(min length and max length should be specified):9845098450

and these numbers are separated by ma(+919845098450,9845098450 etc) so for i have done it for single phone number .

^([+])?[0-9()\-#+]*$

and ma separated

^([+])?[,\d{9}]*$

but the above regex is not showing error when the input ends with ma (+919845098450,9845098450,).

I need to do it for ma separated numbers in jquery/javascript.

if possible i need to specify min and max length with and without country code. your help is appreciated.

Need to validate phone numbers which are separated by ma and it can have country code as start parameter. I need to do temporary validation in front end side such as validating different numbers

  1. number with country code(min length and max length should be specified): +919845098450
  2. number without country code(min length and max length should be specified):9845098450

and these numbers are separated by ma(+919845098450,9845098450 etc) so for i have done it for single phone number .

^([+])?[0-9()\-#+]*$

and ma separated

^([+])?[,\d{9}]*$

but the above regex is not showing error when the input ends with ma (+919845098450,9845098450,).

I need to do it for ma separated numbers in jquery/javascript.

if possible i need to specify min and max length with and without country code. your help is appreciated.

Share Improve this question edited Jul 8, 2015 at 6:54 NoobEditor 15.9k20 gold badges85 silver badges117 bronze badges asked Jul 8, 2015 at 6:52 Madhukar HebbarMadhukar Hebbar 3,1835 gold badges45 silver badges71 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You may try this,

/^(?:\+\d{2})?\d{10}(?:,(?:\+\d{2})?\d{10})*$/.test(str);

DEMO

  • (?:\+\d{2})? helps to match an optional country code.
  • \d{10} matches the 10 digit number.
  • (?:,(?:\+\d{2})?\d{10})* helps to match the following zero or more phone numbers.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745474965a4629305.html

相关推荐

  • javascript - Phone number regex validation - Stack Overflow

    Need to validate phone numbers which are separated by ma and it can have country code as start paramete

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信