In the id_1 form, I would like to check in the id_1 (text input) field if someone entered the numbers - if so - to block the form from being sent. It’s a first name field, but standard filtering (mask or regex) can’t handle the examples
Paweł and Ewa
Paul
(two names are okay, names can contain special characters (for a given language) - the only idea is to check if there is a digit or number in this field and display an error.
I tried with a filter like this:
add_filter ('gform_field_validation', function ($ result, $ value, $ form, $ field) {
if ($ field-> type == 'name') {
// Input values
$ fullName = rgar ($ value, $ field-> id. '.3');
if (empty ($ fullName)) {
$ result ['is_valid'] = false;
$ result ['message'] = empty ($ field-> errorMessage)? __ ('This field is required. Please enter a complete name.', 'Gravityforms'): $ field-> errorMessage;
} else if (preg_match ('/ [A-Za-z]. * [0-9] | [0-9]. * [A-Za-z] /', $ fullName)) {// check for letters only
$ result ['is_valid'] = false;
$ result ['message'] = empty ($ field-> errorMessage)? __ ('Full name must ony contains letters.', 'Gravityforms'): $ field-> errorMessage;
} else {
$ result ['is_valid'] = true;
$ result ['message'] = '';
}
}
return $ result; // return results
}, 10, 4);
but it does not work reliably for special characters (like ą, ć, ż, ć, ü, ö, ä or other specific to different languages)
How to do it?