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.
[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
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
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:
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
JavaScript Regex Tester – Test any regex patterns live.
Base64 Encoder – Encode sensitive strings before sending them over the web.
Token Generator – Generate secure tokens with your regex rules.
CSV to JSON Converter – Handle large imports of SSNs for validation and storage.