Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ancaa

    (@ancaa)

    Hello,

    The validation process functions correctly; however, there’s an issue with the auto flag and dial number disappearing upon form submission containing letters. Numbers alone submit correctly, same for numbers and letters.

    Thank you

    Thread Starter ancaa

    (@ancaa)

    This problem is for auto flag countries

    Thread Starter ancaa

    (@ancaa)

    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);
Viewing 3 replies - 1 through 3 (of 3 total)