Generating valid social security numbers

SSN’s cannot use 000, 666, or 900-999 for the first three digits
In addition, they cannot use 00 or 0000 for the 2nd set of digits and 3rd set of digits respectively.

I am trying to setup a schema that will generate valid SSN numbers.

Currently, I have a Field called _ssn that is of type SSN that will generate my initial SSN number but these can include numbers in the 900-999 range. I have not seen it generate 000 or 666 yet so cannot say if those get excluded by Mockaroo or not.

I then have a field called ssn that is of type Formula with the following formula:

if (_ssn[0…2] != “000”) and (_ssn[0…2] != “666”) and (_ssn[0…0] != “9”) then _ssn else _ssn.gsub(/^\d{1}/, ‘8’) end

Any numbers I have seen from the 900-999 get the first digit changed from 9 to 8 as I would expect. Again, I haven’t seen any 000 or 666 pop up in my data so cannot confirm it would work for these numbers if it did.

My problem now lies with the middle two digits being 00 or the last 4 digits being 0000. I’ve tried similar approaches to change on of the digits to something else but it never works for me.

Anyone have any advice on this? Thanks in advance.

Sadly I was unaware of this until now. So thank you for posting this! I’ve published an update with guarantees SSNs will be valid based on the requirements you described.

Awesome. I’ve done a few test runs and it looks good so far.

Very much appreciated.