javascript - Phone number regex validation -


need validate phone numbers separated comma , can have country code start parameter. need temporary validation in front end side such validating different numbers

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

and these numbers separated comma(+919845098450,9845098450 etc) have done single phone number .

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

and comma separated

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

but above regex not showing error when input ends comma (+919845098450,9845098450,).

i need comma separated numbers in jquery/javascript.

if possible need specify min , max length , without country code. appreciated.

you may try this,

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

demo

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

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -