4

Need to validate phone numbers which are separated by comma 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 comma(+919845098450,9845098450 etc) so for i have done it for single phone number .

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

and comma separated

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

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

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

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

NoobEditor
  • 15,563
  • 19
  • 81
  • 112
Madhukar Hebbar
  • 3,113
  • 5
  • 41
  • 69

1 Answers1

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.
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274