- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
^(?!000)(?!666)(?<SSN3>[0-6]\d{2}|7(?:[0-6]\d|7[012]))([- ]?)(?!00)(?<SSN2>\d\d)\1(?!0000)(?<SSN4>\d{4})$
Updated on 3/4/2004 per feedback to additionally exclude SSNs that begin with 666 which, as reported, are also not valid. Regular expression for validating US Social Security Numbers. Accepts optional hyphens or spaces as formatting characters. Parses the three subfields of the SSN into three named sub-strings (SSN1, SSN2, and SSN3) to facilitate program use. Rejects matches on all zeros for any individual subfield of the Social Security Number. Matches only on those SSNs that fall within the range of numbers currently allocated by the Social Security Administration.
111223333 | 111-22-3333 | 111 22 3333
111003333 | 111 22-3333 | 666-22-3333
Author Rating: Not yet rated. Jerry Schmersahl
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: This might cover it . . .
Name: JP Honeywell
Date: 6/17/2004 6:56:01 PM
^(?!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}$ If anyone thinks they can tidy this up even more, be my guest.

Title: Not only 666 apparently . . .
Name: JP Honeywell
Date: 6/17/2004 6:19:16 PM
Looking at the following URL, I see that as of 6/1/2004 there are several areas (that's what the 1st three digits are called) that are not valid. I'll save your eyes a bit. The invalid areas are: 588 666 691-699 734-763 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: Error in Internet Explorer 6
Name: JJ
Date: 6/5/2004 5:00:14 PM
Does not work with IE6

Title: IE 6
Name: ej
Date: 5/5/2004 12:07:20 PM
errors in javascript using ie 6

Title: SSN by Jerry Schmersahl
Name: Don Johnston
Date: 3/3/2004 2:48:43 PM
Excellent edit of currently issued SSNs. The only invalid numbers I was able to add without the expression catching them were SSNs beginning with 666. SSA has not issued any of these numbers and will not issue them in the future. Overall a superb espression which makes good use of subexpressions and backreferencing.

Copyright © 2001-2021, | ASP.NET Tutorials