Regex for accepting all types of phone numbers in JavaScript validation

I am currently using below regex to receive phone numbers,

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

      

But now I want it to also accept the following phone numbers (specifically for Indian mobiles and landlines):

+91 9970464878 + 91-22-22221500 09970464878 9970464878

+3


source to share


1 answer


You can add three possibilities to the beginning of a regular expression.

This is the regex I once used for a similar requirement:

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

      



NOTE . You will have to remove all the hyphens as I don't think they are really necessary for validation.

Test example

The following is a description of a Regular Expression Regulator .

+2


source







All Articles