title: conditional validation depending on 2 elements
body: <p>Using jquery validation I have used the .addMethod to add a regular expression.   I also have a rule if a checkbox is not checked, then it will require the element be filled out as well as comply with the regex. </p>
  
  <p>noPreviousEmployers is the id of the checkbox  that if checked it should not display any validation messages, if it is not checked then it will display the required message and if it has data in the input it should run the regex</p>
  
  <pre><code>    $.validator.addMethod("regex", function (value, element, regexpr) {
         return regexpr.test(value);
      }, "");
  
  
  rules:{
      EndSalary1:{
          required: '#noPreviousEmployers:unchecked', 
          regex: /^\$?[0-9]{1,3}(\,?\d{3})?(\,?\d{3})?(\.[0-9]{2})?$/
      }
  
  },
  messages:{  
      EndSalary1:{
           required: "Required Field", 
           regex: "Format As US Currency"
      }    
  }
  </code></pre>
  
  <p>I have even tried with this</p>
  
  <pre><code>$.validator.addMethod("regex", function (value, element, regexpr) {
      if(value.length != 0){
          return regexpr.test(value);
      }
  }, "");     
  </code></pre>
  
  <p>when I test with the checkbox checked and no data in the field it will  display the message for regex validation.  It should not display anything in this instance.</p>