I am trying to validate that a number is a social security number.
Can REGEX expressions be used in a number field, much like the built-in phone number field works? Or better yet- a built-in SSN field that validates a) 9 digit number in the format of 3-2-4 and b) that it is actually a VALID 9 digit SSN (a la http://www.ssa.gov/employer/highgroup.txt and jrez.com's function that validates the SSN usinga GNU function)
//.
I have started to build a validated function for this, but I find that I am using the field so often on so many forms, it is becoming cumbersome customizing for which field that function fires
Here is my function, but it was starting to get out of control"
//add_filter('gform_validation', 'valid_ssn');
function valid_ssn($validation_result){
$form = $validation_result["form"];
// if not form ID 2, return result unmodified
if($form["id"] != 2)
return $validation_result;
if (isset($_POST['input_3'])){
if ( !isValidSSN($_POST['input_3'])){
// set the form validation to false
$validation_result["is_valid"] = false;
$form = $validation_result["form"];
// specify the first field to be invalid and provide custom validation message
$form["fields"][2]["failed_validation"] = true;
$form["fields"][2]["validation_message"] = "This is an invalid Social Security Number. Please check.";
// update the form in the validation result with the form object you modified
$validation_result["form"] = $form;
return $validation_result;
}else {
$validation_result["is_valid"] = true;
$form = $validation_result["form"];
//return $validation_result;
}
}