Social Security Number (SSN) Validation Regex
Validate US Social Security Numbers in XXX-XX-XXXX format with this regex pattern.
Pattern & Test String
About This Pattern
Pattern: ^\d{3}-\d{2}-\d{4}$
Flags: g
Results
Enter a regex pattern to see the results here.
Frequently Asked Questions
Does this validate if the SSN is actually issued?
No, this only validates format. The Social Security Administration doesn't provide an API to verify SSNs.
Should I collect or store SSNs?
Only if absolutely necessary and with proper security measures. SSNs are sensitive PII requiring encryption at rest and in transit.
What if the SSN is entered without dashes?
You can make dashes optional: ^\d{3}-?\d{2}-?\d{4}$ or normalize input by removing dashes before validation.
Practical Examples
Tax Form Validation
Validate SSN format on tax or financial forms.
Identity Verification
Format validation as part of identity verification processes.
HR Systems
Validate employee SSN entries in payroll systems.
Common Issues & Solutions
This pattern accepts invalid SSNs like 000-00-0000 or 666-xx-xxxx. Add specific validation rules if needed.
Always encrypt SSNs in storage and transit. Use TLS for transmission and AES-256 for storage.
Consider using last 4 digits only for display purposes to minimize exposure.
NEVER log SSNs. Mask them in logs: XXX-XX-1234