Regex for US Social Security Number
Matches US Social Security Numbers in XXX-XX-XXXX format with basic invalid range exclusions.
Pattern
/^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$/Pattern Breakdown
| Token | Explanation |
|---|---|
| ^ | Start of string |
| (?!000|666|9\d{2}) | Area number not 000, 666, or 900-999 |
| \d{3} | Three-digit area number |
| - | Dash separator |
| (?!00) | Group number not 00 |
| \d{2} | Two-digit group number |
| - | Dash separator |
| (?!0000) | Serial number not 0000 |
| \d{4} | Four-digit serial number |
| $ | End of string |
Test Examples
| Input | Match? |
|---|---|
| 123-45-6789 | Match |
| 001-01-0001 | Match |
| 000-12-3456 | No match |
| 666-12-3456 | No match |
| 123-00-3456 | No match |
Common Use Cases
- Identity verification form validation
- Data masking and detection
- Compliance scanning
Variations
^\d{3}-\d{2}-\d{4}$Simple format check without range validation
^\d{9}$Nine digits without dashes
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester