3

I'm currently using below regex for accepting phone numbers,

 /^\+?(\d[.\- ]*){9,12}(e?xt?\d{1,5})?$/;

But now I want it to accept following phone numbers also(specially Indian mobile and landlines):

+91 9970464878 +91-22-22221500 09970464878 9970464878

Vilas
  • 837
  • 2
  • 15
  • 41

1 Answers1

2

You can add the 3 possiblities to the start of the regex.

This is the regex I once used on a similiar requirement :

^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?\d{10}$

NOTE - You will have to strip away all the hyphens, as I dont think they are really required for validations.

Sample Test

Here is the Regular Expression Analyzer explanation.

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
  • Does this [link](http://www.myezapp.com/apps/dev/regexp/show.ws?regex=%5E%28%3F%3A%28%3F%3A%5C+%7C0%7B0%2C2%7D%2991%28%5Cs*%5B%5C-%5D%5Cs*%29%3F%7C%5B0%5D%3F%29%3F%5Cd%7B10%7D%24&env=env_js) explain? – Rohit Vipin Mathews Jun 01 '15 at 09:31
  • This [SO Question](https://stackoverflow.com/questions/2491930/is-there-an-online-regexbuddy-like-regular-expression-analyzer) has some great answers to Regex Analyzers – Rohit Vipin Mathews Jun 01 '15 at 09:38