Created
January 17, 2013 19:29
-
-
Save ataylorme/4558871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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