SSN Regex for 123-45-6789 OR XXX-XX-XXXX

To strictly answer you question:

^(123-45-6789|XXX-XX-XXXX)$

should work. 😉

If you read the section “Valid SSNs” on Wikipedia`s SSN article then it becomes clear that a regex for SSN validation is a bit more complicated.

Accordingly a little bit more accurate pure SSN regex would look like this:

^(?!(000|666|9))\d{3}-(?!00)\d{2}-(?!0000)\d{4}$

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)