T
ToolPrime

Regex for US Social Security Number

Validates 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}$/

Live Tester

Enter a string to test

Examples

123-45-6789
001-01-0001
768-01-1234
000-45-6789
123-00-6789
123-45-0000

Pattern Breakdown

^(?!000|666|9\d{2})\d{3} — area number (001-665, 667-899)

-(?!00)\d{2} — group number (01-99)

-(?!0000)\d{4}$ — serial number (0001-9999)

Code Snippets

Javascript

const regex = /^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$/;
regex.test("123-45-6789"); // true

Python

import re
pattern = r"^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$"
bool(re.match(pattern, "123-45-6789"))  # True

Php

$pattern = '/^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$/';
preg_match($pattern, "123-45-6789"); // 1

Related Patterns

Frequently Asked Questions

What is the regex for US Social Security Number?
The regex pattern for US Social Security Number is /^(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}$/. Validates US Social Security Numbers in XXX-XX-XXXX format with basic invalid-range exclusions.
How do I use the US Social Security Number regex in JavaScript?
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the US Social Security Number pattern match?
It matches strings like 123-45-6789; it rejects strings like 000-45-6789. See the Examples section above for the full list of matching and non-matching cases.

Related Tools