title: jQuery: How to validate date using multiple formats?
body: <p>I would like to validate an input field as being a valid date, but I would like to specify the date format on a case-by-case basis. Something like:</p>
  
  <pre><code>&lt;input id="date" type="text" data-validate="true" data-val-date="mm/dd/yyyy"&gt;
  
  &lt;input id="date-two" type="text" data-validate="true" data-val-date="dd-mm-yy"&gt;
  </code></pre>
  
  <p>My validation looks like:</p>
  
  <pre><code>// inputValue is the value of the input
  // typeValue is the value of data-val-date
  
  var comp = inputValue.split('/');
  var m = parseInt(comp[0], 10);
  var d = parseInt(comp[1], 10);
  var y = parseInt(comp[2], 10);
  
  var date = new Date(y,m-1,d);
  
  if (date.getFullYear() == y &amp;&amp; date.getMonth() + 1 == m &amp;&amp; date.getDate() == d) {
  
      return true; // Passed
  
  else {
  
      return false; // Error
  
  }
  </code></pre>
  
  <p>This works when the date format is ALWAYS <code>mm/dd/yy</code>, but how can I tweak this to use whatever format is passed using the <code>data-val-date</code> attribute?</p>
  
  <p>The m,d and y letters will always be the same. I just need to check how many characters each should be (mm or m, yy or yyyy, etc), and I need to see what the separator is (/,-, etc).</p>