title: jQuery validation, Date Format mm/yyyy validates on keyup
body: <p>I need to validate my input fields before processing it to payment using Stripe.</p>
  
  <p>For card number I created an input box:</p>
  
  <pre><code>&lt;input type="text" class="credit-card" id="cardnumber" name="cardnumber" size="30" value="" placeholder="XXXX-XXXX-XXXX-XXXX"&gt;
  </code></pre>
  
  <p>I validate it in a manner that after every 4 digits it put <code>-</code> automatically:</p>
  
  <pre><code>String.prototype.toCardFormat = function () {
       return this.replace(/[^0-9]/g, "").substr(0, 16).split("").reduce(cardFormat, "");
  function cardFormat(str, l, i) {
      return str + ((!i || (i % 4)) ? "" : "-") + l;
     }
  };
  $(".credit-card").keyup(function () {
        $(this).val($(this).val().toCardFormat());
  });
  </code></pre>
  
  <p>Now I need to validate the date as the user start entering <code>mm</code>, it automatically adds <code>/</code> and make it in format <code>mm/yyyy</code> . So that this should be valid date:</p>
  
  <pre><code>05/2016
  </code></pre>
  
  <p>but not these:</p>
  
  <pre><code>13/2018
  05/2006
  5/19
  05/19
  06-2019
  05 2019
  </code></pre>
  
  <p>Also I used replace method to restrict user to enter ant text and symbols.</p>