InRegex Logo
InRegex
New

Match American Social Security Number

Explanation

This regex pattern matches American Social Security Numbers. It first uses \b to match word boundaries. Then it uses negative lookahead assertions to exclude invalid SSN patterns like ones starting with 000, 666, or in the 900-999 range. It then matches the standard SSN format of '###-##-####'.

python

Regular Expression

\\b(?!000|666|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0000)\\d{4}\\b
Copy
Do you have Feedback?
python

Example Usage

import re

ssn_pattern = r'\b(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}\b'
ssn = '123-45-6789'
if re.match(ssn_pattern, ssn):
    print('Valid SSN')
Copy

Test the expression

Similar Regular Expressions