Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation for a 10 digit phone number

Tags:

regex

I'm looking for a simple regex that will validate a 10 digit phone number. I'd like to make sure that the number is exactly 10 digits, no letters, hyphens or parens and that the first two digits do not start with 0 or 1. Can someone help out?

like image 731
jon Avatar asked Dec 26 '09 21:12

jon


People also ask

How do I validate a 10 digit mobile number?

you can also use jquery for this length==10){ var validate = true; } else { alert('Please put 10 digit mobile number'); var validate = false; } } else { alert('Not a valid number'); var validate = false; } if(validate){ //number is equal to 10 digit or number is not string enter code here... }

How do I validate a mobile number?

Mobile Number validation criteria:The first digit should contain numbers between 6 to 9. The rest 9 digit can contain any number between 0 to 9. The mobile number can have 11 digits also by including 0 at the starting. The mobile number can be of 12 digits also by including 91 at the starting.

How do I create a 10 digit mobile number in Salesforce?

US Phone Number Has Ten Digits Validates that the Phone number is in (999) 999-9999 format. This works by using the REGEX function to check that the number has ten digits in the (999) 999-9999 format.


2 Answers

/[2-9]{2}\d{8}/

like image 98
mopoke Avatar answered Oct 17 '22 21:10

mopoke


^[2-9]{2}[0-9]{8}$

I consider [0-9] to be better to read than \d, especially considering the preceding [2-9]

The ^ and $ ensure that the input string consists ONLY of those 8 characters - otherwise it is not guaranteed that the input string is not larger - i.e. "12345678901" would match the regex w/o those two characters - although it is 11 chars and starts with a 1!

like image 33
gha.st Avatar answered Oct 17 '22 19:10

gha.st