Validationflags: g

US Social Security Number

Match US Social Security Numbers in the canonical XXX-XX-XXXX format.

Try it in RegexPro →

Available in

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).

Pattern

regexengine-agnostic
\b\d{3}-\d{2}-\d{4}\b   (flags: g)

Raw source: \b\d{3}-\d{2}-\d{4}\b

How it 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-6789

Matches

  • 123-45-6789

Input

SSN: 987-65-4321 on file

Matches

  • 987-65-4321

Input

123456789

No match

Common use cases

  • PII detection in logs or documents
  • Data loss prevention (DLP) scanning
  • Form field validation in US apps
  • Redaction pipelines for compliance

Related patterns