I am using webform-8.x-5.0 and created a telephone field with international phone numbers support. Before submitting the form if i enter some number like "+91fdfgdfg45646" it shows "Invalid phone number" (which i am not sure if it is a valid number or not). But when I submit the form it gets submitted. The issue is if it is invalid, the form should not have been submitted. Please suggest a solution. The form should not be submitted if it is invalid number.

Thanks in advance

Image for reference: Invalid phone number

| improve this question | | | | |

The international phone number element is only a client-side enhancement which is using the International Telephone Input library.

To validate the phone number via server-side validation you would need write custom code and to use a PHP library like https://github.com/giggsey/libphonenumber-for-php

| improve this answer | | | | |
  • 1
    The form shouldn't really submit if validation fails though (if it's using JS to validate the form it can also use JS to stop the submission) would that be a bug that needs to be raised or is this expected/inevitable behaviour? – Clive Apr 5 '18 at 9:11
  • I think this should be addressed the International Telephone Input library but I would be open to committing enhancements to the Webform module's 'Advance Telephone' element's server-side validation. – jrockowitz Apr 12 '18 at 14:47
  • Admittedly I don't know the specifics of the implementation, but I wouldn't expect a JS filter library to stop a form submitting itself. I'd expect it to provide a boolean response, on demand, to the question "is this field valid", and then for my code to decide whether or not the form should be submitted based on that. Probably a discussion for the issue queue though. Might have some tie later, if I do I'll chuck a patch up – Clive Apr 12 '18 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.