Title |
Test
Find
Pattern Title
|
Expression |
^(?:(?<1>[(])?(?<AreaCode>[2-9]\d{2})(?(1)[)])(?(1)(?<2>[ ])|(?:(?<3>[-])|(?<4>[ ])))?)?(?<Prefix>[1-9]\d{2})(?(AreaCode)(?:(?(1)(?(2)[- ]|[-]?))|(?(3)[-])|(?(4)[- ]))|[- ]?)(?<Suffix>\d{4})$ |
Description |
Regular expression for validating US telephone numbers with OPTIONAL area code. Matches various permutations of formatting characters (parenthesis, space, dash). Parses the telephone number area code, prefix, and suffix to named groups to facilitate program manipulation. Area code is optional and can optionally be enclosed in parentheses. Rejects area codes that begin with 0 or 1 and prefixes that begin with 0. Rejects all telephone numbers that do not match on exactly 7 digits, or on exactly 10 digits with the optional area code, not counting the formatting characters. |
Matches |
333-4444 | 222 333 4444 | (222) 333-4444 |
Non-Matches |
222333 4444 | 222-333 4444 | (222)-333 4444 |
Author |
Rating:
Jerry Schmersahl
|
Source |
|
Your Rating |
|
Title: Syntax Error
Name: Lucy
Date: 1/20/2005 1:09:02 PM
Comment:
I received a javascript error while running this validation. The error says Invalid Regular Expression Syntax. Please advice. You can reach me at [email protected]
Thanks