0

Form Validation: If data in Multi-Line form contains "VP-", display alert. I'm trying to do code that errors out a form validate if the form contains "VP-".

In a previous thread I found out how to do this on a 1-line submit, but how about multi-line?

Previous thread is here: Form Validation: If data in form contains "VP-", error out

My code is below:

  <form method='post' name='QuickOrder' onSubmit='return validateQuickOrder(this)'     style="position: relative">
  <div id="DmiACwrap">
    <input type="hidden" name="formName" value="dmiformQuickOrder">
    <input type='Text' name="ProductNumber" id="ProductNumber" title="Enter Product #">
    <input type='Text' name="ProductNumber" id="ProductNumber" title="Enter Product #">
    <input type='Text' name="ProductNumber" id="ProductNumber" title="Enter Product #">
    <input type='Text' name="ProductNumber" id="ProductNumber" title="Enter Product #">
    <input type='Text' name="ProductNumber" id="ProductNumber" title="Enter Product #">
    <input type="submit" class="quick-order-add" value="Add">
  </div>
  </form>

// quick order form validation
function validateQuickOrder(form) {        
  if ((form.ProductNumber.value == "")|| (~form.ProductNumber.value.indexOf('VP') > -1)){
        alert("Please enter an item number.");
        form.ProductNumber.focus();
        return false;
 }
        return true;

}

Community
  • 1
  • 1
James Anderson
  • 815
  • 1
  • 13
  • 23
  • Maybe you need to revisit some JavaScript basics... I'd suggest the [MDN](https://developer.mozilla.org/en-US/docs/JavaScript). Once you've explored _all_ possible options, debugged your code with console and passed the JSLint test that's when you seek help on SO, otherwise you'll never learn anything, and your code will be a messy copy/paste hieroglyph. – elclanrs Jan 03 '13 at 19:48
  • Proof exists of bad copy/pasting already, look `(~form.ProductNumber.value.indexOf('VP') > -1)` and compare to the accepted [answer of your last question](http://stackoverflow.com/questions/14145525/form-validation-if-data-in-form-contains-vp-error-out). See what I mean? – elclanrs Jan 03 '13 at 19:51
  • Neither of these helped - I'll clarify what I'm looking for. I'm trying to perform form validation using the same JS statement above on each field. Each field is the same thing; a product number that I want to make sure that the strings do not contain "VP" using that JS. For some reason, can't get it to work the same way the single line did. – James Anderson Jan 03 '13 at 20:03

0 Answers0