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
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (US) /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
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.