This regex pattern matches the American Social Security number format, which consists of three digits, a hyphen, two digits, another hyphen, and four digits. The \b ensures that it matches the whole Social Security number as a separate word.
const regex = /\b\d{3}-\d{2}-\d{4}\b/;
const ssn = '123-45-6789';
console.log(regex.test(ssn)); // Output: true
Copiar