I use the below IF statement to validate a single text field input box called "PhoneNum" on submit. It allows either blank, or 10 digits. I need to apply this logic to all fields with the word "PhoneNum" in the text box name. The fields are added dynamically, so I need to look for all input boxes with "Phonenum" in the name.
I'd like to keep it in an if statement, and use jQuery to do this, with something like: $("[name*=PhoneNum]").....
Could someone assist?
var PhoneNum = $("#PhoneNum").val(); if(/^(\d{0}|\d{10})$/.test(PhoneNum) == false) { alert("All Phone Number fields can only contain 10 digits."); $( "#PhoneNum" ).focus(); return false; }
$([name*="PhoneNum"]).each(function(){var PhoneNum = $( this .val(); if(/^(\d{0}|\d{10})$/.test(PhoneNum) == false) { alert("All Phone Number fields can only contain 10 digits."); $( this ).focus(); return false; }});
Open in new window