Gagan
Gagan

Reputation: 163

regex for comma separated valid mobile numbers

I've found following regex that can validate multiple email addresses (comma separated)

/^(\s?[^\s,]+@[^\s,]+\.[^\s,]+\s?,)*(\s?[^\s,]+@[^\s,]+\.[^\s,]+)$/

I also have this regex that can check for valid Indian mobile numbers, ie. 10 digit numeric starting with [6,7,8 or 9] only

/[6-9]{1}\d{9}/

I am looking for a regex that can test a comma separated list of mobile numbers.

let mobilePattern = /[6-9]{1}\d{9}/;
console.log(mobilePattern.test('8223822382')); // valid
console.log(mobilePattern.test('3223822382')); // invalid start with 3
console.log(mobilePattern.test('823822382')); // invalid 9 digits

Upvotes: 0

Views: 334

Answers (1)

Yo can try with this:

/[6-9]\d{9}(,[6-9]\d{9})*/

If you wants that contains exactly that format you can try:

/^[6-9]\d{9}(,[6-9]\d{9})*$/

Upvotes: 3

Related Questions