The social security numbers I want to accept are as follows:
xxx-xx-xxxx (ex. 123-45-6789)
xxxxxxxxx (ex. 123456789)
xxx xx xxxx (ex. 123 45 6789)
I'm not a regex expert, but I wrote this (it's kind of ugly)
^(\d{3}-\d{2}-\d{4})|(\d{3}\d{2}\d{4})|(\d{3}\s{1}\d{2}\s{1}\d{4})$
However, this social security number passes when it should really fail, because there is only one space
12345 6789
So I need an updated regex that rejects things like
12345 6789
123 456789
To make things more complicated, it seems that SSNs cannot start with 000 or 666 and can go up to 899, the second and third set of numbers also cannot be all 0.
I came up with this
^(?!000|666)[0-8][0-9]{2}[ \-](?!00)[0-9]{2}[ \-](?!0000)[0-9]{4}$
Which is checked with spaces or dashes, but it fails if the number looks like
123456789
Ideally, this SSN set should go through
123456789
123 45 6789
123-45-6789
899-45-6789
001-23-4567
And they must fail
12345 6789
123 456789
123x45x6789
ABCDEEEEE
1234567890123
000-45-6789
123-00-6789
123-45-0000
666-45-6789