title: javascript date validation not validation February 31
body: <p>I am trying to write some code with will validate form data. I have a date field which should have a <code>mm/dd/yyyy</code> format. I needed to catch exceptions such as <em>February 31</em>, so I added this code:</p>
  
  <pre><code>var d = new Date(dob);
  if (isNaN(d.getTime())) { //this if is to take care of February 31, BUT IT DOESN'T!
    error = 1;
    message += "&lt;li&gt;Invalid Date&lt;/li&gt;";
  } else {
    var date_regex = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/;
    var validFormat = date_regex.test(dob);
    if (!(validFormat)) {
      error = 1;
      message += "&lt;li&gt;Invalid date format - date must have format mm/dd/yyyy&lt;/li&gt;";
    }
  }
  </code></pre>
  
  <p>However I found something very weird: while the date <em>02/32/2000</em> errors as an invalid date, <em>02/31/2000</em> does not!</p>