I'm trying to do code that errors out a form validate if the form contains "VP-".
My code is:
// quick order form validation
function validateQuickOrder(form) {
if ((form.ProductNumber.value == "")|| (form.ProductNumber.value == "VP")){
alert("Please enter an item number.");
form.ProductNumber.focus();
return false;
}
return true;
}
==
does a full string comparison. You'll want to useindexOf
to check if it contains that string:The tilde is a neat trick, but you can be more verbose if you want:
Just to provide an alternative to the other answer, regex can be used as well: