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})(?:[ ]?[xX]?(?<Ext>\d{2,4}))?$ |
Description |
Regular expression for validating US telephone numbers with OPTIONAL area code, and OPTIONAL extension. Matches various permutations of formatting characters (parenthesis, space, dash). Parses the telephone number area code, prefix, suffix, and extension 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. Extension is optional and can be optionally preceded by a space and/or "x" or "X", and matches on 2 to 4 digits. 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 extension or the formatting characters. |
Matches |
333-4444 | (222) 333-4444 | 222-333-4444 X55 |
Non-Matches |
222333 4444 | (222)-333 4444 | 333-4444-5555 |
Author |
Rating:
Jerry Schmersahl
|
Source |
|
Your Rating |
|
Title: fails test
Name: developer
Date: 12/25/2004 5:48:06 PM
Comment:
doesn't work for examples
Title: Got Error in IE 6
Name: Kyle
Date: 7/6/2004 5:48:34 PM
Comment:
Got Error in IE 6
Title: IE6
Name: JJ
Date: 6/5/2004 5:16:05 PM
Comment:
Doesn't work with IE6