title: How do I validate a date in this format (yyyy-mm-dd) using jquery?
body: <p>I am attempting to validate a date in this format: (yyyy-mm-dd).  I found this solution but it is in the wrong format for what I need, as in: (mm/dd/yyyy).</p>
  
  <p>Here is the link to that solution: <a href="http://jsfiddle.net/ravi1989/EywSP/848/" rel="noreferrer">http://jsfiddle.net/ravi1989/EywSP/848/</a></p>
  
  <p>My code is below:</p>
  
  <pre><code>function isDate(txtDate)
  {
      var currVal = txtDate;
      if(currVal == '')
          return false;
  
      var rxDatePattern = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/; //Declare Regex
      var dtArray = currVal.match(rxDatePattern); // is format OK?
  
      if (dtArray == null) 
          return false;
  
      //Checks for mm/dd/yyyy format.
      dtMonth = dtArray[1];
      dtDay= dtArray[3];
      dtYear = dtArray[5];        
  
      if (dtMonth &lt; 1 || dtMonth &gt; 12) 
          return false;
      else if (dtDay &lt; 1 || dtDay&gt; 31) 
          return false;
      else if ((dtMonth==4 || dtMonth==6 || dtMonth==9 || dtMonth==11) &amp;&amp; dtDay ==31) 
          return false;
      else if (dtMonth == 2) 
      {
          var isleap = (dtYear % 4 == 0 &amp;&amp; (dtYear % 100 != 0 || dtYear % 400 == 0));
          if (dtDay&gt; 29 || (dtDay ==29 &amp;&amp; !isleap)) 
                  return false;
      }
      return true;
  }
  </code></pre>
  
  <p>What regex pattern can I use for this that will account for invalid dates and leap years?</p>