Skip to content

Instantly share code, notes, and snippets.

@ataylorme
Created January 17, 2013 19:29
Show Gist options
  • Save ataylorme/4558871 to your computer and use it in GitHub Desktop.
Save ataylorme/4558871 to your computer and use it in GitHub Desktop.
$.validator.addMethod('SocialSecurity',
function (value) {
return validSSN(value) || value == "";
}, 'Please enter a valid SSN'
);
function validSSN(value) {
var regex = /^([0-6]\d{2}|7[0-6]\d|77[0-2])([ \-]?)(\d{2})\2(\d{4})$/;
if (!regex.test(value)) {
return false;
}
var temp = value;
if (value.indexOf("-") != -1) {
temp = (value.split("-")).join("");
}
if (value.indexOf(" ") != -1) {
temp = (value.split(" ")).join("");
}
if (temp.substring(0, 3) == "000") {
return false;
}
if (temp.substring(3, 5) == "00") {
return false;
}
if (temp.substring(5, 9) == "0000") {
return false;
}
return true;
}//end validSSN function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment