The Gravity form phone number field is supposed to validate a telephone number, but if the field option is set to “international” then the form submits if the data in the field are standard characters.
The code below hooks into my form and specific field, but I am having problems with how to check if the field string is a number.
// add custom validation to the gravity forms plugin to validate "phone number" field
add_filter("gform_field_validation_2_4", "custom_validation", 10, 4);
function custom_validation($result, $value, $form, $field){
if($result["is_valid"] && intval($value)){
$result["is_valid"] = false;
$result["message"] = "Please enter a valid telephone number";
}
return $result;
}
I would appreciate your advice and feedback.
Thanks,
JB.
Why don’t you try with a regular expression? It works great for such cases. For example (untested):