Pattern library / Numbers & Codes
Regex to Match US Social Security Numbers (SSN)
Matches the canonical XXX-XX-XXXX shape. Regex validates format only — it does not verify the number is issued or valid; do that against SSA rules in code.
How the pattern works
(?!000|666|9\d{2})— area number cannot be 000, 666, or 900-999.(?!00)— group number cannot be 00.(?!0000)— serial number cannot be 0000.- RE2 supports negative lookahead, so this works in GA4 and BigQuery.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
123-45-6789 | Match | valid shape | Try → |
000-45-6789 | No match | area 000 invalid | Try → |
666-45-6789 | No match | area 666 invalid | Try → |
123-00-6789 | No match | group 00 invalid | Try → |
123-45-0000 | No match | serial 0000 invalid | Try → |
123456789 | No match | missing dashes | Try → |
Where to use it
JavaScript
const re = /^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$/;
re.test('123-45-6789'); // true
Python
import re
re.match(r'^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$', '123-45-6789')
Common mistakes
Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
FAQ
Related patterns
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.