Does anyone have an idea how to put a phone validation on this website? http://www.wmgb.com/ on the homepage there is a “Get a Free Qoute” Contact form and I want to have the visitor put in a valid US phone number like this “(111)-111-1111”? I’m trying to do jQuery function for this. How can I prevent the form from submitting if the phone number is incorrect? Thanks in advance.
Bear in mind that front-end scripting cannot be relied upon entirely for validation, it will only help honest users from making errors. It can be bypassed or fail if js is not working for whatever reason.
Also in modern browsers, the pattern attribute can do all that bit for you anyway.
For secure validation, it has to be done server-side as part of the form processing.
it shouldn’t even be used any more at all now that you can apply the validation using HTML.
To validate a phone number as much as is appropriate in the browser you just need type=“tel” instead of type=“text” in the input tag. The rst of the validation can be done on the server (where it needs to be done anyway).
The form was actually made from contact form 7. I’ve been searching how to add a filter and found some forums but the their code for validating phone number doesn’t work anymore. Probably because it was an old post.