title: JQuery validate date between a date range
body: <p>I've an input field where users can insert a date between a date range.</p>
  
  <p>So I added a new method on JQuery validator object:</p>
  
  <pre><code>$.validator.addMethod("dateRange", function(value, element, from, to){
      try {
          var date = new Date(value);
          if(date &gt;= from &amp;&amp; date &lt;= to)
              return true;
      } catch(e) {
      }
      return false;
  }
  </code></pre>
  
  <p>Then I added a new class rules:</p>
  
  <pre><code>$.validator.addClassRules({
      myDateFieldRangeValidate: {
          dateRange: {fromDate, toDate}
      }
  });
  </code></pre>
  
  <p>And finally I added the class to the input:</p>
  
  <pre><code>$("#myField").addClass("myDateFieldRangeValidate");
  </code></pre>
  
  <p>So, how can I pass the two dates to the validation function?</p>
  
  <p><strong>UPDATE: Added a code snippet</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$.validator.addMethod("dateRange", function(value, element, from, to){
      try {
          var date = new Date(value);
          if(date &gt;= from &amp;&amp; date &lt;= to)
              return true;
      } catch(e) {
      }
      return false;
  });
  
  var fromDate = new Date("2017-02-01");
  var toDate = new Date("2017-12-31");
  
  $.validator.addClassRules({
      myDateFieldRangeValidate: {
          dateRange: {fromDate, toDate}
      }
  });
  
  $("#myField").addClass("myDateFieldRangeValidate");
  
  $("#btnValidate").click(function(){
    $("#frm1").validate();
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/additional-methods.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"&gt;&lt;/script&gt;
  &lt;form id="frm1"&gt;
    Date &lt;input type="text" id="myField"&gt;
    &lt;input type="button" id="btnValidate" value="Validate"&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>