SSN Pattern

Based on http://regexlib.com/REDetails.aspx?regexp_id=2850 which includes better validation based on rules defined in wikipedia.

This pattern matches the entire string if it contains an SSN pattern that is NOT surrounded by other number (ex: 00001-01-000100 will NOT match).

first line : start of line OR anything followed by at least one non-numeric/carriage return
second line : first group of numbers (cannot be 000 or 666, etc)
third line : optional hyphen separator
fourth line : second group of numbers (cannot be 00)
fifth line : optional hyphen separator
sixth line : third group of numbers (cannot be 0000)
seventh line : end of line OR at least one non-numeric/carriage return followed by anything
Language:
RegEx
Keywords:
RegEx
Code Snippet

(^|^(.*[^0-9|\r\n]))

((?!000)(?!666)(?:[0-6]\d{2}|7[0-2][0-9]|73[0-3]|7[5-6][0-9]|77[0-2]))

-?

((?!00)\d{2})

-?

((?!0000)\d{4})

(([^0-9|\r\n]+.*)$|$)


Created 2015-04-28
comments powered by Disqus
Login