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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])? (?!00)\d\d([ -|])? (?!0000)\d{4}$
Description
U.S. social security numbers (SSN), within the range of numbers that have been currently allocated. Matches the pattern AAA-GG-SSSS, AAA GG SSSS, AAA-GG SSSS, AAA GG-SSSS, AAAGGSSSS, AAA-GGSSSS, AAAGG-SSSS, AAAGG SSSS or AAA GGSSSS. All zero in any one field is not allowed. ** Additionally, spaces and/or dashes and/or nothing are allowed. In Michael Ash's example 123-45 6789 and 123456789 would fail there was a '\3' after the second octet of numbers that seemed to confuse the regex. now any combination of spaces, dashes, or nothing will work between the SSN octets. BoxerX.com thanks Michael for the regex!
Matches
145470191 | 145 47 0191 | 145-47 0191
Non-Matches
000470191 | 145-00-0191 | 145.47.0191
Author Rating: The rating for this expression. Joe Johnston
Source This is a modification of Michael Ash's SSN regex
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: A slight bug
Name: Michael Ash
Date: 7/27/2004 12:59:42 PM
Comment:
The is a bug in this regex that will allow 123-45Z6789 or 0123456789 (too many digits) If you can't figure out this "gotcha" after a minute or two check out http://blogs.regexadvice.com/mash/archive/2004/06/17/1272.aspx


Title: The Purpose of \3
Name: Michael Ash
Date: 7/27/2004 12:46:27 PM
Comment:
Joe, the purpose of the backreference \3 was to enforce the use of the same field separator throughout the string. You could use spaces or hyphens but not both.


Title: SSN REgex
Name: Joe Johnston
Date: 7/27/2004 11:03:32 AM
Comment:
Hey, I gotta give myself and Mike some snaps. Don't I?


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