Anyone out there know how to improve this function? I'm not worried about shortening the code, I'm sure this could be done with better regex, I am more concerned about correct logic. I have had a terrible time finding documentation for SSN #'s. Most of the rules I use below have come from other programmers who work in the credit industry (no sources cited).
Are there any additional rules that you are aware of?
Do you know if any of this is wrong?
Can you site your sources?
public static bool isSSN(string ssn) { Regex rxBadSSN = new Regex(@"(\d)\1\1\1\1\1\1\1\1"); //Must be 9 bytes if(ssn.Trim().Length != 9) return false; //Must be numeric if(!isNumeric(ssn)) return false; //Must be less than 772999999 if( (Int32)Double.Parse(ssn.Substring(0,3)) > 772 ) { //Check for Green Card Temp SSN holders // Could be 900700000 // 900800000 if(ssn.Substring(0,1) != "9") return false; if(ssn.Substring(3,1) != "7" && ssn.Substring(3,1) != "8") return false; } //Obviously Fake! if(ssn == "123456789") return false; //Try again! if(ssn == "123121234") return false; //No single group can have all zeros if(ssn.Substring(0,3) == "000") return false; if(ssn.Substring(3,2) == "00") return false; if(ssn.Substring(5,4) == "0000") return false; //Check to make sure the SSN number is not repeating if (rxBadSSN.IsMatch(ssn)) return false; return true; }
It should be divided into 3 parts by hyphen (-). The first part should have 3 digits and should not be 000, 666, or between 900 and 999. The second part should have 2 digits and it should be from 01 to 99. The third part should have 4 digits and it should be from 0001 to 9999.
Structure. The Social Security number is a nine-digit number in the format "AAA-GG-SSSS".
UPDATE
On June 25, 2011, the SSA changed the SSN assignment process to "SSN randomization".[27] SSN randomization affects the SSN assignment process in the following ways:
It eliminates the geographical significance of the first three digits of the SSN, previously referred to as the Area Number, by no longer allocating the Area Numbers for assignment to individuals in specific states. It eliminates the significance of the highest Group Number and, as a result, the High Group List is frozen in time and can be used for validation of SSNs issued prior to the randomization implementation date. Previously unassigned Area Numbers have been introduced for assignment excluding Area Numbers 000, 666 and 900–999.
New Rules
http://en.wikipedia.org/wiki/Social_Security_number#Structure
Previous Answer
Here's the most-complete description of the makeup of an SSN that I have found.
As of 2011 SSN's are completely randomized (http://www.socialsecurity.gov/employer/randomization.html)
The only real rules left are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With