RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find US Phone with/without Extension (.NET)
Expression
\(?(\d{3})(?:\)*|\)\s*-*|\.*|\s*|/*|)(\d{3})(?:\)*|-*|\.*|\s*|/*|)(\d{4})(?:\s?|,\s?)
Description
Fairly universal regex for matching any US Phone number in .net. It basically matches the 10 digit phone number using the common US patterns, and allows for any text after the fact. I use it with the .replace method and pull out "$1$2$3" to get the pure 10-digit phone number, and anything after that is just stored as additional text. this additional text could be an extension, daytime information, hours, etc.
Matches
9405551234, (940) 555-1234, 940.555.1234, 940-555-1234, 940-555-1234 x5000, 940-555-1234, ext. 5000, 940-555-1234 8-5pm
Non-Matches
94055512345, 9401-546-5468, or any other non-10-digit, non-standard pattern
Author Rating: Not yet rated. Jorin Slaybaugh
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

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: 940-555-1234
Name: DOES NOT WORK
Date: 4/12/2007 12:32:03 PM
Comment:
940-555-1234 *DOES NOT WORK


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials