Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
40
rated 0 times [  43] [ 3]  / answers: 1 / hits: 30494  / 13 Years ago, mon, december 26, 2011, 12:00:00

I need to validate phone or mobile number in javascript.

It should match the following types:

+91-9198387083

9198387083

09198387083

It is a 10 digit number with one of these four prefixes '+91-', '+91', '0' or ''


Can someone suggest me a regex expression in javascript which matches all the three types.


More From » regex

 Answers
3

I'd using something like this:



/^(+91-|+91|0)?d{10}$/


This is very specific about one of your three allowable prefixes (or no prefix) followed by exactly 10 digits and no extra characters on the beginning of end of the string.



Test app with both valid and invalid phone numbers here: http://jsfiddle.net/jfriend00/K9bjL/


[#88372] Friday, December 23, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
denzelc

Total Points: 637
Total Questions: 89
Total Answers: 88

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;