Hi I have a question, this regax is being used to validate phone number what are they trying to do here?
$phone_regex = "/(\([2-9]\d{2}\)\s?|[2-9]\d{2}-|[2-9]\d{2})[1-9]\d{2}-?\d{4}/";
trying to understand this regex
Moderator: General Moderators
-
nickvd
- DevNet Resident
- Posts: 1027
- Joined: Thu Mar 10, 2005 5:27 pm
- Location: Southern Ontario
- Contact:
Code: Select all
/
( begin grouping
\( look for a literal bracket
[2-9] followed by a single number between 2 and 9
\d{2} followed by two digits (0-9)
\) followed by a literal bracket
\s? there may or may not be a space after the bracket
| OR
[2-9] a single digit (2-9)
\d{2} followed by two digits
- followed by a hyphen
| OR
[2-9] a single digit (2-9)
\d{2} followed by two digits
) end grouping
[1-9] followed by a digit from 1-9
\d{2} followed by two more digits from 0-9
-? followed by a hyphen (that may or not be there)
\d{4} followed by 4 digits (0-9)
/- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA