Need to verify U.S. Social Security Numbers during form validation or API testing? The Qodex SSN Regex Go Validator helps you check SSNs against standard formats instantly. Pair it with tools like the Username Generator, Phone Number Generator, or Address Generator to simulate realistic user data for testing your Go applications.
[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 SSN Regex?
In Go (or Golang), regular expressions are handled via the built-in regexp package, allowing developers to match and validate text with precision.
A Social Security Number (SSN) in the U.S. has a fixed format: AAA-GG-SSSS, where:
AAA is the area number (3 digits)
GG is the group number (2 digits)
SSSS is the serial number (4 digits)
To validate this structure, regex provides a simple and efficient solution using the pattern:
This pattern ensures:
Three digits
Followed by a dash
Then two digits
Another dash
And four final digits
Core Features & Benefits
Format-Specific: Strictly enforces U.S. SSN format.
Instant Validation: Works immediately in Go with regexp.MustCompile.
Safe Testing: Avoid using real data—test your systems with dummy values.
Reusable Regex: Easily incorporate this pattern into your Go codebase.
Compatible with Multiple Tools: Works great with UUID Generator, MAC Address Generator, and Phone Number Regex Go Validator for full simulation.
Example Code in Go
Pro Tips for Using SSN Regex in Go
Use Anchors for Full Match: Always wrap your regex with ^ and $ to ensure the entire string is validated and not just a substring.
Avoid Real Data in Tests: Never use actual SSNs in testing environments. Instead, simulate them using tools like the Username Generator, Phone Number Generator, or Address Generator to create complete mock profiles.
Precompile for Performance: Use regexp.MustCompile() outside of loops or functions to precompile your regex and improve performance, especially in large-scale apps.
Validate Format, Not Identity: Regex only checks structure. To validate real SSNs, integrate with a verification API or official database.
Use Logging for Debugging: While testing your Go regex logic, add logs to track matches and mismatches. This will help catch formatting issues early.
Common Use Cases
Form Validation: Ensure users enter SSNs in the correct format.
Onboarding Systems: Verify identification during user registration.
Data Cleansing: Clean up and standardize SSN fields in your database.
Compliance Systems: Enforce format validation for privacy-sensitive workflows.
Combine With These Tools
Use the SSN Validator with these Qodex tools for complete profile simulation and testing:
Phone Number Generator – Generate U.S. numbers to pair with SSNs.
Address Generator – Create fake yet realistic U.S. addresses for mock user data.
Email Generator – Build full user profiles for form testing.
UUID Generator – Assign unique identifiers to each mock user.
MAC Address Generator – Useful for simulating device-based identity.
Regex Tester for Go – Validate any pattern directly in your Go applications.
Regex for Other Languages
Want to test SSNs in other languages?
JavaScript: Use in JavaScript Regex Tester
Python: Try in Python Regex Tester
Java: Validate in Java Regex Tester