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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(?=((0[1-9]0)|([1-7][1-7]\d)|(00[1-9])|(0[1-9][1-9]))-(?=(([1-9]0)|(0[1-9])|([1-9][1-9]))-(?=((\d{3}[1-9])$|([1-9]\d{3})$|(\d[1-9]\d{2})$|(\d{2}[1-9]\d)$))))
Description
I wrote this regular expression because a project I was working on required a stricter validator on social security numbers. There are actually gov't standards on what is a valid social: The first 3 digits can't be > 779, The first 3 digits can't be 000, The second 2 digits can't be 00, and the last 4 digits can't be 0000. This regex handles all these cases and checks formatting for numbering and dashes (###-##-####)
Matches
053-27-0293 | 770-29-2012 | 063-71-9123
Non-Matches
780-20-1230 | 000-24-1290 | 123-00-1239
Author Rating: Not yet rated. Scott Long
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: Two fixes
Name: Shawn K. Hall
Date: 10/16/2003 2:06:35 PM
Comment:
There were two bugs in this regex: It didn't account for SSN's in the format [1-7]0n-nn-nnnn or for anything in the range of [1-6][8-9]n-nn-nnnn Those are resolved with this correction: ^(?=((0[1-9]0)|([1-7][0-7]\d)|([1-6][0-9]\d)|(00[1-9])|(0[1-9][1-9]))-(?=(([1-9]0)|(0[1-9])|([1-9][1-9]))-(?=((\d{3}[1-9])$|([1-9]\d{3})$|(\d[1-9]\d{2})$|(\d{2}[1-9]\d)$)))) Great work though!


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