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)11111111"); //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; }