title: How to use jQuery Validator to compare two fields
body: <p>I want to validate 2 input fields by comparing one to the other and make sure the second is greater than the first. </p>
  
  <p>Do I need to add a custom method or can I just use the variable name in the range method? If so, can you point me to the syntax?</p>
  
  <pre><code>var validateSection = function (theForm) {
  $(theForm).validate({
      rules: {
          startPoint: {
              required: true,
              range: [0, 100]
          },
          endPoint: {
              required: true,
              range: [startPoint + 1, 100] //Is this possible if I set the function to run on any change to either field?
          },
  }
  });
  
  if ($(theForm).valid()) {
      return true;
  }
  else {
      return false;
  }
  }
  </code></pre>
  
  <p>Code with Custom Method:</p>
  
  <pre><code>$.validator.addMethod("endGreaterThanBegin", function(value, element) {
      return endPoint &gt; startPoint
  }, "* End Point Should be Greater than Start");
  
  var validateSection = function (theForm) {
      $(theForm).validate({
          rules: {
              startPoint: {
                  required: true,
                  range: [0, 100]
              },
              endPoint: {
                  required: true,
                  range: [1, 100],
                  endGreaterThanBegin: true
              },
          }
      });
      if ($(theForm).valid()) {
          return true;
      }
      else {
          return false;
      }
  }
  </code></pre>
  
  <p>Getting $.validator is undefined before I get to form, and then validateSection is not a function when I start testing input fields</p>