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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Social Security Number
Expression
^(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -]?)(?!00)\d\d\3(?!0000)\d{4}$
Description
This regex validates U.S. social security numbers, within the range of numbers that have been currently allocated.
Matches
078-05-1120 | 078 05 1120 | 078051120
Non-Matches
987-65-4320 | 000-00-0000 | (555) 555-5555
Author Rating: The rating for this expression. Michael Ash
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: Social Security Number expression
Name: Passemails
Date: 6/20/2013 5:06:34 PM
Comment:
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: cheapjerseysab@163.com
Date: 10/28/2012 10:45:08 PM
Comment:
There’s been <a href="http://www.pick-cheapjerseys.com/ ">CheapJerseys.com</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="http://www.pick-cheapjerseys.com/ ">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="http://www.pick-cheapjerseys.com/ ">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 www.6pmsjerseys.com USA
Name: myjerseys
Date: 10/4/2012 6:35:34 AM
Comment:
The <a href="http://www.6pmsjerseys.com/ ">Cheap Jerseys</a> best of that bunch I listed above was <a href="http://www.6pmsjerseys.com/ ">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="http://www.6pmsjerseys.com/ ">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
Comment:
www.belekproperties.com/belekproperties.aspx?id=84&bagliid=0 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=154 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=137 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=159 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=168 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=169 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=144 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=184 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=82 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=66 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=76 www.belekproperties.com/belek_apartment_for_sale_details.aspx?id=157 www.belekproperties.com/belek_villa_for_sale_details.aspx?id=36


Title: Wholesale Authentic Cheap Nike NFL Jerseys
Name: topandgd
Date: 6/24/2012 7:36:02 AM
Comment:
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 CheapJerseys.com http://www.6pmjerseys.com


Title: cheap beats by dr.dre
Name: cheap beats by dr.dre
Date: 5/24/2012 10:31:27 PM
Comment:
Both <a href="http://www.beatsbydrdrer.com/"><strong>Beats By Dre Headphones</strong></a> and <a href="http://www.beatsbydrdrer.com/"><strong>Cheap Beats By Dre</strong></a> have high quality、efficient Service .With advanced speaker design, powered amplification, and active noise canceling, <a href="http://www.beatsbydrdrer.com/"><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
Comment:
Both [url=http://www.beatsbydrdrer.com/][b]Beats By Dre Headphones[/b][/url] and [url=http://www.beatsbydrdrer.com/][b]Cheap Beats By Dre[/b][/url] have high quality、efficient Service .With advanced speaker design, powered amplification, and active noise canceling, [url=http://www.beatsbydrdrer.com/][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
Comment:
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: http://www.magicianmatchmakers.com/magicians/IL/


Title: Excelent bit of code
Name: Bill
Date: 12/8/2011 12:05:12 PM
Comment:
Very handy. But RegExLib.com 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
Comment:
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]http://www.hats-world.com[/url] [url]http://www.wholesale-cheap-newerahats.com/[/url]


Title: wholesale new era hats
Name: new era hats
Date: 8/3/2011 4:53:47 AM
Comment:
This really answered my problem, thank you! <a href=" http://www.hats-world.com">new era hats</a> <a href=" http://www.wholesale-cheap-newerahats.com/">wholesale new era hats</a>


Title: Magicians in Philadelphia
Name: Magicians in Philadelphia
Date: 1/31/2011 12:04:18 AM
Comment:
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! http://www.magiciansinphiladelphia.org


Title: Cheap handbag wholesaler
Name: Cheap handbag sale
Date: 1/12/2011 8:34:40 PM
Comment:
http://www.bagsduffel.com/versace-handbag-purse-c-1_12.html Over the past five years, the rapid progress of construction of housing support is five years, from the Ministry of Housing and Urban Construction of the data showed that the "Eleventh Five-Year" period, http://www.bagsduffel.com/juicy-couture-handbags-c-1_15.html through a variety of affordable housing construction, China solved the low-income urban households and 11.4 million 3.6 million middle-income family housing problems. http://www.bagsduffel.com


Title: ugg boots
Name: ugg boots
Date: 12/12/2010 8:41:16 AM
Comment:
Every people work hard to earn money to live a good life.me too.As a guys of ugg australia.I want to tell people that more about info from inner of Ugg Australia marketing department.the profit of one pair of ugg boots is very high!if you cost 300 USD to buy a Ugg lady boots,in fact,the most of cost is only about 60-100 usd.So what is the best way to get a "ugly boots" in a lowest price? The right answer is get it from a www.ugg-official-website.com ,this is a only one online shop who get right of selling genuine ugg boots from Ugg Australia. But this site is not know by lots of people,becoz it is only face to inner worker of company.Now I come here and share it with every one who want to have a genuine ugg boots in a lower price than buy from shop. The most cold winter is coming this years.Go and own a Ugg boots to keep our foots warm.Let us have a wonderful time in this winter ! Go for 1 pair now -> www.ugg-official-website.com


Title: http://www.nfljerseynet.com
Name: sell-nfljerseyscom
Date: 11/13/2010 9:26:29 AM
Comment:
sell-nfljerseyscom http://www.nfljerseynet.com nfljerseynet@hotmail.com NFL ,MLB,NBA,NHL jerseys We can supply all kind jersey with good quality and low price. http://www.sell-nfljerseys.com http://www.nfljerseynet.com


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


Title: Exclude one number set?
Name: David Neal
Date: 6/2/2010 2:14:53 PM
Comment:
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
Comment:
Thanks, this saved me a headache :)


Title: Thank you
Name: Vlad
Date: 2/4/2009 10:26:03 AM
Comment:
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
Comment:
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
Comment:
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
Comment:
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
Comment:
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
Comment:
good


Title: 10 digit execeptions
Name: Don Turnblade
Date: 9/15/2004 7:30:17 PM
Comment:
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 DTurnblade@Ameriquest.com


Title: Re: Description revision suggestion
Name: Michael Ash
Date: 7/28/2004 5:36:31 PM
Comment:
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
Comment:
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
Comment:
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
Comment:
According to the regex Jerry did http://www.regexlib.com/REDetails.aspx?regexp_id=539 there are some areas other than 773 and above which are also invalid. As of 6/1/2004 and according to http://www.ssa.gov/foia/highgroup.htm and http://www.ssa.gov/foia/stateweb.html, 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
Comment:
I had created a functionally identical expression that was much bulkier after reading the cspr.org (and before finding www.regexlib.com). 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-2014, RegexAdvice.com | ASP.NET Tutorials