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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(^|\s)(00[1-9]|0[1-9]0|0[1-9][1-9]|[1-6]\d{2}|7[0-6]\d|77[0-2])(-?|[\. ])([1-9]0|0[1-9]|[1-9][1-9])\3(\d{3}[1-9]|[1-9]\d{3}|\d[1-9]\d{2}|\d{2}[1-9]\d)($|\s|[;:,!\.\?])
Description
Incorporated other people's examples; removed extraneous parenthesis on 10/7/04. Currently the SSA site says 772 is the highest AREA number generated (http://www.ssa.gov/employer/highgroup.txt). Old expression was: (^|\s)\d{3}(-?|[\. ])\d{2}\2\d{4}($|\s|[;:,!\.\?]). Looks for either the beginning of a line or whitespace before the beginning of the social security number, then either zero or one hyphen OR one of a period or space, then uses the \3 to reference the value returned in the parenthesis that includes the -?|[\. ] (basically says if the first dash, period, or space is there, then the second one is required; and if the first dash, period, or space is not there, then the second one can't be either), and finally looks for the end of a line, whitespace, or punctuation characters after the social security number.
Matches
123-45-6789 | 123 45 6789 | 123456789
Non-Matches
12345-67-890123 | 1234-56-7890 | 123-45-78901
Author Rating: The rating for this expression. Dennis Flynn
Source Flynnstone
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: Clever way to restrict/enforce dashes
Name: Jim Kimble
Date: 1/21/2004 5:16:22 AM
Comment:
Clever way to restrict or enforce the use of hyphens delimiting the number groups: the input can use any legal form so long as its decision is consistent throughout the pattern. That's simliar to 'sed' which allows any character to be used as the pattern delimiter: sed 's/foo/bar/g' and sed 's,foo,bar,g' and sed 's|foo|bar|g' are functionally identical. Not only cool, it's resilient.


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