Conversation
supportHello, When I submit letters instead of numbers the country code and flag dissapears. How can I manage this situation in order to keep this two when submitting? The error is showing correct message, the letters remain in the field but those two dissapears. I used this code but no success $(document).ready(function() { var phoneField = $('.ginput_container_phone input'); if(phoneField.length) { var originalCountryCode = ''; var originalFlagClass = ''; phoneField.on('input', function() { var value = phoneField.val(); var countryCodeMatch = value.match(/^\+\d+/); var countryCode = countryCodeMatch ? countryCodeMatch[0] : ''; // Save the country code and flag class if it exists if (countryCode) { originalCountryCode = countryCode; originalFlagClass = $('.iti__selected-flag').attr('class'); } // Remove the country code from the value to process the rest of the input var numberPart = value.replace(/^\+\d+/, ''); // Set the input value to the original country code plus the rest of the input phoneField.val((originalCountryCode ? originalCountryCode : '') + numberPart); // Restore the flag and dial code elements if they are not visible if (!$('.iti__selected-flag').hasClass('iti__flag') || !$('.iti__selected-dial-code').text()) { $('.iti__selected-flag').attr('class', originalFlagClass); $('.iti__selected-dial-code').text(originalCountryCode); } // Re-trigger the plugin's validation or refresh method, if available if (phoneField.intlTelInput) { phoneField.intlTelInput("setNumber", phoneField.val()); } }); } });
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);
This problem is for auto flag countries
Hi, @ancaa , Thanks for your support threads. Gravity forms allow letters in the phone field. For this reason, it accepts text/letters. I am checking this issue. I will fix it with javascript and update here soon. Thanks for your patience. This reply was modified 2 years ago by Kaisar Ahmmed .
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
Hi @ancaa Please update the plugin. Letter submitting issue is fixed. Thanks
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);
This problem is for auto flag countries
Hi, @ancaa , Thanks for your support threads. Gravity forms allow letters in the phone field. For this reason, it accepts text/letters. I am checking this issue. I will fix it with javascript and update here soon. Thanks for your patience. This reply was modified 2 years ago by Kaisar Ahmmed .
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
Hi @ancaa Please update the plugin. Letter submitting issue is fixed. Thanks