add_filter('gform_field_validation', function($result, $value, $form, $field) {
// Check if the field is the phone field you want to validate
if ($field->type == 'phone') {
$lang = get_locale();
$phone_message_form = "Please enter a valid phone number.";
$messages = [
"de_DE" => "Bitte geben Sie eine gültige Telefonnummer ein.",
"es_ES" => "Por favor, introduzca un número de teléfono válido.",
"nl_NL" => "Voer een geldig telefoonnummer in.",
"en_US" => "Please enter a valid phone number."
];
if (array_key_exists($lang, $messages)) {
$phone_message_form = $messages[$lang];
}
// Allow letters and digits in the phone field
if (!preg_match('/^[a-zA-Z0-9\s\+\-\(\)\[\]\/]*$/', $value)) {
$result['is_valid'] = false;
$result['message'] = $phone_message_form;
}
}
return $result;
}, 10, 4);