Form validation help
-
I am trying to write a script that will go into the additional setting tab that will force a text box to only allow 5 digits ie a zip code to be entered. I can’t seem to get it to work; here is what I have so far Text-686 is a required field. Any help would be appreciated.
<script> document.addEventListener('wpcf7mailsent', function (event) { var formId = '5d7e827'; (event.detail.contactFormId == formId) { var inputValue = document.querySelector('form[id="' + formId + '"] input[name="text-686"]').value; // Check if the input value is exactly 5 digits if (!/^\d{5}$/.test(inputValue)) { alert('Please enter exactly 5 numbers in the "Shipping Zipcode" field.'); event.preventDefault(); // Prevent the form submission return false; // Stop further execution } } }, false); </script>
The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Form validation help’ is closed to new replies.