- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Social Security Number
^(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -]?)(?!00)\d\d\3(?!0000)\d{4}$
This regex validates U.S. social security numbers, within the range of numbers that have been currently allocated.
078-05-1120 | 078 05 1120 | 078051120
987-65-4320 | 000-00-0000 | (555) 555-5555
Author Rating: The rating for this expression. Michael Ash
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: Social Security Number expression
Name: Passemails
Date: 6/20/2013 5:06:34 PM
Hi Michael Ash I am currently using the expression for ssn /// Validates the format of the SSN provided using the regular expression pattern /// Either /// first character - 0 to 6 /// next two characters - 0 to 9 /// or /// first character is 7 /// and either /// second character is 0 to 6 /// third character is 0 to 9 /// or /// second character is 7 /// third character is either 0, 1, or 2 /// fourth and fifth characters cannot be SPACE and DASH combination /// fourth and fifth characters cannot be 00 /// fourth character is 0 to 9 /// fifth character is 0 to 9 /// sixth character is 0 to 9 /// seventh character is 0 to 9 /// eighth character is 0 to 9 /// ninth character is 0 to 9 Regex(@"^([0- 6]\d{2}|7([0-6]\d|7[012]))([ -]?)(?!00)\d\d\3\d{4}$") Now I want to have expression to validate the ssn with following condition. 1. Cannot use or accept "666" in positions 1-3 2. Cannot use or accept "000" in positions 1-3 3. Cannot use or accept "00" in positions 4-5 4. Cannot use or accept "0000" in positions 6-9 5. If SSN begins with "9" ignore all other edits. I know my expression will do this. But except the above condition other pattern should match. Say ,first digit should accept 8

Title: cheapjersey
Name: [email protected]
Date: 10/28/2012 10:45:08 PM
There’s been <a href=" "></a> considerable chatter, but zero reports, that the Broncos would be a possible destination for Maurice Jones-Drew if the Jacksonville running back were put on the trading block. The <a href=" ">Cheap Jerseys</a> speculation no doubt has something to do with the fact Jones-Drew’s former coach in Jacksonville, Jack Del Rio, is now the <a href=" ">Cheap Jerseys USA</a> Broncos’ defensive coordinator. At this point, the Broncos would not be in play. They like the potential crash-n-dash tailback tandem they have in Willis McGahee and Ronnie Hillman, provided Hillman can get his nagging hamstring healed. Together, McGahee and Hillman will make $3.08 million this year. Jones-Drew is protesting his contract that pays him a $4.45 million this year. Baltimore just gave Ray Rice a contract extension that pays him $17 million this year and $25 million in the next two years so Jones-Drew has the right to feel slighted. But it would be difficult for the Broncos to satisfy him. Consider the Broncos are already paying a combined $53 million of their $120 million cash-to-cap budget this year to four players: Peyton Manning ($18 million), Elvis Dumervil ($14 million), Champ Bailey ($10.5 million) and Von Miller ($10.5 million). That’s 44 percent of the team’s 61-man (including practice squad) payroll. The team is also hoping to sign left tackle Ryan Clady after this season to a $10 million a year deal.

Title: Get Cheap Authentic Jerseys at USA
Name: myjerseys
Date: 10/4/2012 6:35:34 AM
The <a href=" ">Cheap Jerseys</a> best of that bunch I listed above was <a href=" ">Cheap Jerseys USA</a> Darrent Williams, who helped Bailey have two of his best seasons in 2005 and 2006. Bailey had 18 interceptions in those two years. Williams was murdered on Jan. 1, 2007 in arguably the most tragic incident in team history For <a href=" ">Cheap Authentic Jerseys</a>. Andre Goodman started 40 games at right corner over the last three years but was released this spring. The Broncos signed 26-year-old Tracy Porter and are hoping that Porter will be an upgrade. “My goal is to stop them from throwing to my side, just like Champ’s is to stop them from throwing to the other side. They’ll have to find another way to get it to the receivers – that’s the goal,” Porter said. “If I wasn’t up for that challenge, knowing that Champ is on the other side, I could have easily signed somewhere else.” So, I ask you, Broncos fans, what are your expectations for Porter? Do you think he’s an upgrade over Goodman? What is your interception prediction for the Broncos’ secondary this year?

Title: Belek Properties
Name: Turkey Investment Turkish Property For Sale For Rent
Date: 7/3/2012 8:50:30 AM

Title: Wholesale Authentic Cheap Nike NFL Jerseys
Name: topandgd
Date: 6/24/2012 7:36:02 AM
Wholesale Cheap Authentic NFL Jerseys USA: Customized NFL NHL MLB NBA jerseys, Cheap Nike NFL jerseys, Women MLB hats Caps, youth soccer jerseys, NHL kids jerseys, Reebok NHL jerseys and NBA jerseys for sale

Title: cheap beats by dr.dre
Name: cheap beats by dr.dre
Date: 5/24/2012 10:31:27 PM
Both <a href=""><strong>Beats By Dre Headphones</strong></a> and <a href=""><strong>Cheap Beats By Dre</strong></a> have high quality、efficient Service .With advanced speaker design, powered amplification, and active noise canceling, <a href=""><strong>Beats By Dre Sale</strong></a> delivers all the power, clarity, and deep bass today's top artists and producers want you to hear.We are looking forward to forming successful business relationships with new clients around the world.

Title: Beats By Dre Studio
Name: Beats By Dre Studio
Date: 5/24/2012 10:19:48 PM
Both [url=][b]Beats By Dre Headphones[/b][/url] and [url=][b]Cheap Beats By Dre[/b][/url] have high quality、efficient Service .With advanced speaker design, powered amplification, and active noise canceling, [url=][b]Beats By Dre Sale[/b][/url] delivers all the power, clarity, and deep bass today's top artists and producers want you to hear.We are looking forward to forming successful business relationships with new clients around the world.

Title: Very cool code
Name: Deepak
Date: 1/9/2012 3:53:16 PM
This is a good piece of code. For our sites though, we're not using anything with social security numbers. More of just credit cards. Here's our site:

Title: Excelent bit of code
Name: Bill
Date: 12/8/2011 12:05:12 PM
Very handy. But needs to scrub thier comments for SPAM.

Title: wholesale new era hats
Name: wholesale new era hats
Date: 8/5/2011 5:02:08 AM
Your place is valueble for me. Thanks!…This web site is really a walk-through for all of the info you wanted about this and didn’t know who to ask. Glimpse here, and you’ll definitely discover it. [url][/url] [url][/url]

Title: wholesale new era hats
Name: new era hats
Date: 8/3/2011 4:53:47 AM
This really answered my problem, thank you! <a href="">new era hats</a> <a href="">wholesale new era hats</a>

Title: Magicians in Philadelphia
Name: Magicians in Philadelphia
Date: 1/31/2011 12:04:18 AM
Amazing the thought that goes into this. I'll be showing this to my programmer so he can see the kind of magic that is being done here!

Title: High quality NFL jerseys with Cheap Price!
Name: Buy cheap NFL jerseys
Date: 9/3/2010 9:25:02 PM
hello,want high quality nfl jerseys with cheap price? want a suprise? go to ! ---

Title: Exclude one number set?
Name: David Neal
Date: 6/2/2010 2:14:53 PM
Michael, would it be possible with this RegEx (or another SSN filter) to modify it to exclude exactly ONE number that I specify? Like, for instance, 123456789.

Title: You rock
Name: David
Date: 5/28/2010 9:30:58 AM
Thanks, this saved me a headache :)

Title: Thank you
Name: Vlad
Date: 2/4/2009 10:26:03 AM
Thank you for the great code.

Title: An update for the benefit of DTSearch use
Name: Don Turnblade
Date: 11/3/2008 12:52:25 PM
DTSearch of all files on a files system may not begin and end at nice field boundaries. The following is an update inspired by Michael's work that may be useful that limits the string found to 9 digits by requiring a non-number terminator place. Also, by using non-number field separators, differing user habits in number separators are accounted for. Below is a change and a description of its workings: (?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([^0-9]{1,1}?)(?!00)\d{2}\3(?!0000)\d{4}[^0-9]{1,1} First 3 digits Not 000: ?!000 # Capture results in Buffer 0 Could Be 0##, 1##, 2##, 3##, 4##, 5##, 6##: [0-6]\d{2} # Capture results in Buffer 1 Could Be 70#, 71#, 72#, 73#, 74#, 75#, 76#: 7[0-6]\d # Capture results in Buffer 1 & 2 Could Be 770, 771, 772: 77[012] # Capture results in Buffer 1 & 2 Separator: Not a number, 1 place long or empty: [^0-9]{1,1}? # Capture results in Buffer 3 Next Two digits: Not 00: ?!00 Could be ## \d{2} Separator Reuse Separator found in Buffer 3: \3 Next 4 digits: Not 0000 ?!0000 Could be #### \d{4} Terminating item is not a number Similar to separator but could be different [^0-9]{1,1} This allows for open regular expression searches across file contents where no field begin and end requirement is certain. Using this, allows for finding inappropriate files that hold SSN across file servers. I hope this helps.

Title: Great Code
Name: Hyde
Date: 6/10/2008 4:01:24 PM
Great code, worked the first time as designed and described. Thanks!

Title: The Best!
Name: Ted Cambrom
Date: 2/15/2008 11:39:47 AM
A very nice social security regex. Brilliant! Thank you. Now I have a favorite.

Title: excellent
Name: tsmith
Date: 9/6/2007 4:24:48 PM
great for SSNs; didn't realize the system I put it in needs to accomodate TINs as well. Does anyone know of a regex that handles both?

Title: miss
Name: anna
Date: 7/10/2007 2:48:30 AM

Title: 10 digit execeptions
Name: Don Turnblade
Date: 9/15/2004 7:30:17 PM
I like the fit. I extended the field seperators to any non number with [^0-9]{1,1} 123.45.6789 But I am looking at exluding 10 or more digit strings in the case that non-digit seperators are missing... 123456789 Trying to exclude the following 1234567890 Best Regards, Don Turnblade, CISSP Ameriquest Mortgage Company [email protected]

Title: Re: Description revision suggestion
Name: Michael Ash
Date: 7/28/2004 5:36:31 PM
I don't remember if I was trying to allow there to be no separator between group but your suggestion brought a very strange bug to my attention. The original pattern seen here ^(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -])?(?!00)\d\d\3(?!0000)\d{4}$ Would match 123456789 in Javascpirt but not in .Net. Very odd. Anyway Thanks for the suggestion

Title: Description revision suggestion
Name: L. R. Byers
Date: 7/28/2004 3:08:14 PM
Slight nit-picky revision suggestion for your Description: second sentence should read "Matches the patterns AAA-GG-SSSS or AAA GG SSSS or AAAGGSSSS.", since space or hyphen are optional.

Title: one more thing
Name: JP Honeywell
Date: 6/17/2004 7:17:31 PM
The following areas are classified as "New areas allocated, but not yet issued" 691-699 756-763 752-755 750-751 So 750-763 and 691-699 *could* be valid some day - but who knows when. I wouldn't validate them until they are being assigned.

Title: Very good but could be better
Name: JP Honeywell
Date: 6/17/2004 7:07:09 PM
According to the regex Jerry did there are some areas other than 773 and above which are also invalid. As of 6/1/2004 and according to and, those invalid areas are 588 666 691-699 and 734-763 So I came up with this to update Michael's fine work above. ^(?!000)(?!588)(?!666)(?!69[1-9])(?!73[4-9]|7[4-5]\d|76[0123])([0-6]\d{2}|7([0-6]\d|7[012]))([ -])?(?!00)\d\d\3(?!0000)\d{4}$ Maybe it could be more tidy - I don't know. But it seems to test out ok. Additionally, Issuance of Area numbers 700-728 to railroad employees was discontinued July 1, 1963 so anyone younger than 41 (and probably really 57 [41+16]) should not have a SSN beginning with 700-728. I'm not going to validate that, I don't think.

Title: A very good ssn regex
Name: JP Honeywell
Date: 5/25/2004 2:35:14 PM
I had created a functionally identical expression that was much bulkier after reading the (and before finding Once I saw this I scrapped mine. This regex WILL need to be changed in a few years when SSNs beginning with 773 are issued. But until then this is a good solution. That said, it's not a perfect solution. It is possible to enter invalid SSNs because of the nutty nature of the number assignment scheme. However, making a perfect SSN regex is virtually impossible since the -GG- values are assigned first with odd numbers, 01 to 09, then even numbers, 10 to 98, then even numbers, 02 to 08, and finally odd numbers, 11 to 99. And since those change much faster than the AAA- values it'd be a real bear to stay on top of. Excellent job, Michael.

Copyright © 2001-2024, | ASP.NET Tutorials