US Social Security Number in JS
Match US Social Security Numbers in the canonical XXX-XX-XXXX format.
Try it in the JS tester →Pattern
regexJS
\b\d{3}-\d{2}-\d{4}\b (flags: g)JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("\\b\\d{3}-\\d{2}-\\d{4}\\b", "g");
const input = "123-45-6789";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
Three digits, hyphen, two digits, hyphen, four digits. Word boundaries prevent false matches inside longer digit runs. Note: this pattern does not validate SSN issuance rules.
Examples
Input
123-45-6789Matches
123-45-6789
Input
SSN: 987-65-4321 on fileMatches
987-65-4321
Input
123456789No match
—