SSN Regex Javascript Validator

Search...

⌘K

SSN Regex Javascript Validator

Search...

⌘K


SSN Regex Javascript Validator

SSN Regex Javascript Validator

Easily validate U.S. Social Security Numbers using our JavaScript Regex Tester. This tool ensures your input follows the standard XXX-XX-XXXX format. Whether you’re building secure onboarding flows or cleaning form data, pair it with our Base64 Encoder to protect sensitive info, or convert bulk files using the CSV to JSON Converter. Fast, accurate, and perfect for developers handling identity data.

111-23-9023
Possible security issues
This regex appears to be safe.
Explanation
  • [A-Z]: uppercase letters
  • [a-z]: lowercase letters
  • [0-9]: digits
  • \.: a literal dot
  • +: one or more of the preceding
  • *: zero or more of the preceding
  • ?: optional (zero or one)
  • ^: start of string
  • $: end of string
Match information
Match 1: "111-23-9023" at index 0
Test your APIs today!

Write in plain English — Qodex turns it into secure, ready-to-run tests.

Regular Expression - Documentation

What is an SSN Regex?


In the U.S., a Social Security Number (SSN) is a 9-digit number formatted as XXX-XX-XXXX. Validating this format is crucial in applications where identity verification or data entry accuracy is required.


A regular expression (regex) helps ensure the format is correct before any sensitive operations are performed.


Common SSN Regex Pattern


/^\d{3}-\d{2}-\d{4}$/


What This Pattern Does:

  • ^\d{3}: Start with exactly 3 digits

  • -: A hyphen

  • \d{2}: Followed by 2 digits

  • -: Another hyphen

  • \d{4}$: Ends with 4 digits


Valid SSN: 123-45-6789

Invalid SSN: 12-3456-789 or 123456789


How to Validate SSNs in JavaScript


Here’s a complete JavaScript code example:


function isValidSSN(ssn) {
  const ssnRegex = /^\d{3}-\d{2}-\d{4}$/;
  return ssnRegex.test(ssn);
}

// Example usage:
console.log(isValidSSN("123-45-6789")); // true
console.log(isValidSSN("123456789"));   // false


Where Can SSN Regex Be Used?


  • User Onboarding: Ensure users enter valid SSNs in financial or HR applications.

  • Database Integrity: Catch format errors before saving to your database.

  • Form Validation: Block submissions that don’t follow the expected SSN structure.


Use our JavaScript Regex Tester to experiment with variations or build custom patterns.


Pro Tips


  • Use .test() for fast checks in live form validation.

  • Avoid storing SSNs as plain text. Use the Base64 Encoder to obfuscate values before transmission.

  • For added security, combine regex validation with server-side checks and encryption.

  • Regularly test your regex with mock data using our Random String Generator or Token Generator.

  • Use the CSV to JSON Converter if you’re batch-validating SSNs from user-uploaded files.


Combine with These Tools


Frequently asked questions

Does this regex ensure the SSN is real?×
No. It only checks the format, not whether the number is officially issued.
Can I use this for international IDs?+
Can SSNs have spaces instead of dashes?+
Will this work for real-time form validation?+
Is storing SSNs with regex validation safe?+