tags:

views:

220

answers:

3

I'm looking for a simple regex exp 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?

+6  A: 

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

mopoke
Thank you Mopoke. That works well too. :)
jon
I really have to learn some regex because I'm using it more now than ever before.
jon
When one finds oneself saying to oneself that one should start to learn more about regexps, one should immediately take a step back and reconsider...
Aviad P.
lol.. I agree and have said that before. :)
jon
"qa 12345678901 asd" matches that regex as well
dionadar
+2  A: 

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

bmargulies
Thank you for the answer.
jon
+3  A: 
^[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!

dionadar