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?
Thank you Mopoke. That works well too. :)
jon
2009-12-26 21:22:07
I really have to learn some regex because I'm using it more now than ever before.
jon
2009-12-26 21:22:47
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.
2009-12-26 21:35:09
lol.. I agree and have said that before. :)
jon
2009-12-26 21:45:44
"qa 12345678901 asd" matches that regex as well
dionadar
2009-12-27 17:13:16
+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
2009-12-26 21:36:53