Form validation help | WordPress.org

[ad_1]

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]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer