Monday, July 19, 2004

JavaScript Function to Validate SSN (valid ssn)

This function validates whether or not the passed text is a U.S. social security number, returning True if it is, False if it is not.

ValidSSN - true for valid SSN, false for invalid
function ValidSSN(SSN)
var SSNum = new String(SSN);

var regex = /^[0-9]{3,3}\-[0-9]{2,2}\-[0-9]{4,4}$/;

return regex.test(SSNum);