What is the RegEx to Validate SSN?
Here is the regular expression to validate social security numbers.
Short Answer
^(?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4}$
Longer Answer
Rion Williams has a good blog post with an explanation of the rules.
In a nutshell, social security numbers must not do any of the following:
- Start with
000
,666
, or9
- Have
00
as the middle two digits - Have
0000
as the last four digits - Cannot be
078-05-1120
because of the Woolworth card - Cannot be
219-09-9999
as that appeared in an ad by the SSN administration
The regular expression above validates for all of these conditions, with dashes included.