- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
^([\(]{1}[0-9]{3}[\)]{1}[ |\-]{0,1}|^[0-9]{3}[\-| ])?[0-9]{3}(\-| ){1}[0-9]{4}$
Validates US phone numbers. Phone number can be delimited with dashes or spaces. Area code can optionally include parentheses. To optionally validate area codes, try this expression. ^([\(]{1}[0-9]{3}[\)]{1}[ |\-]{0,1}|^[0-9]{3}[\-| ])?[0-9]{3}(\-| ){1}[0-9]{4}$
(111) 223-2332 | (222)233-2332 | 232-323-3233
(ddd) 223-2332 | 222-232/2333 | 322-3223-222
Author Rating: The rating for this expression. gabe g
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Cleanup and correction
Name: Gideon Engelberth
Date: 4/4/2005 10:36:18 AM
As it is right now, this expression could use a little work. Here's a cleaner and slightly improved version of your expression. ^(\(\d{3}\)[- ]?|\d{3}[- ]?)?\d{3}[- ]?\d{4}$ The changes are: - used \d in place of [0-9] - removed extra beginning of string assertion - removed unneeded quantifiers/character classes - fixed problem with expression matching the | between area code and number (eg (222)|234-5678 would match before) - made all seperators optional (its not impossible to see a phone number as 1235551212, especially among the lazy ones of us) This by no means is a complete fix as the expression will allow some awkward combinations of seperator and no seperator (which could be dealt with using backreferences).

Copyright © 2001-2018, | ASP.NET Tutorials