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 cor
Answer 5 years after initial question due to changes in validation rules by the Social Security Administration. Also there are Specific numbers to invalidate according to this link.
As per my near-2-year-old answer I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.
// validate social security number with ssn parameter as string
function validateSSN(ssn) {
// find area number (1st 3 digits, no longer actually signifies area)
var area = parseInt(ssn.substring(0, 3));
return (
// 9 characters
ssn.length === 9 &&
// basic regex
ssn.match(/^[0-8]{1}[0-9]{2}[0-9]{2}[0-9]{4}/) &&
// disallow Satan's minions from becoming residents of the US
area !== 666 &&
// it's not triple nil
area !== 0 &&
// fun fact: some idiot boss put his secretary's ssn in wallets
// he sold, now it "belongs" to 40000 people
ssn !== '078051120' &&
// was used in an ad by the Social Security Administration
ssn !== '219099999'
);
}
According to updated information there are no other checks to perform.
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.