I am by no means a JS expert and I am setting up form validation on my website. I got most of the validation elements working except for one particular field.
There is a text field in the form called "Group Size". It can't be a number field because sometimes people would enter text like "Approx 20 people", or "40-50". But I am getting some sort of spammy submissions on my form and they will usually put a group size of 1 or 2 or 5. And the email addresses are fake for sure. Anyway, I want to screen these out, so how do I do that? I've also appended the form code.
The conditions I want for the group size field are:
- If the group size field has a length of 1 AND
- The value of the field is less than 6
Then the script returns false and the alert pops up.
Thanks in advance!
Here is the JS and I have highlighted the part that I am stuck on.
function validation(form) {
if(form.first_name.value == '') {
alert('Please enter your first name');
form.first_name.focus();
return false;
}
if(form.last_name.value == '') {
alert('Please enter your last name');
form.last_name.focus();
return false;
}
if(form.company.value == '') {
alert('Please enter your company or organization. *** We do not serve private groups such as birthday parties, wedding parties or other social events ***');
form.company.focus();
return false;
}
if(form.email.value == '') {
alert('Please enter your email address');
form.email.focus();
return false;
}
if (Number(form.00NG0000008iHKH.value) < 6 && form.00NG0000008iHKH.length == 1)
{
alert('Sorry but we are unable to provide programs for groups of 5 or fewer. If you still want to inquire, please phone us.');
form.00NG0000008iHKH.focus();
return false;
}
Bookmarks