Advertisement

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.

The pattern
^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
123-45-6789Matchvalid shapeTry →
000-45-6789No matcharea 000 invalidTry →
666-45-6789No matcharea 666 invalidTry →
123-00-6789No matchgroup 00 invalidTry →
123-45-0000No matchserial 0000 invalidTry →
123456789No matchmissing dashesTry →

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.
Open the regex tester →

FAQ

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.