1

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.

Devashish Dixit
  • 1,153
  • 6
  • 16
  • 25
  • possible duplicates: http://stackoverflow.com/questions/2386054, http://stackoverflow.com/questions/5286046 – Bergi Dec 26 '11 at 17:06

4 Answers4

10

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/

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • @DevashishDixit - you were very quick. I fixed that issue within a minute or so of posting and how there's a test app that you can plug any test values you want into. – jfriend00 Dec 26 '11 at 17:22
0

Something like this should work:

/\+?[0-9]+-?[0-9]/

Alex
  • 32,506
  • 16
  • 106
  • 171
  • This is not very restrictive as it allows any prefix and only matches the first digit of the number itself. – jensgram Dec 26 '11 at 17:15
0

10 digit number with one of these four prefixes +91-, +91, 0 or :

/(\+91-?|0)?\d{10}/
jensgram
  • 31,109
  • 6
  • 81
  • 98
-1
+7 (123) 45-67-890
8(123)381-198-2
and etc.

My simply mask for all of similar phones

/^[+]?(\d[^\d]*){11}$/
DarkAiR
  • 75
  • 2