title: JavaScript Date Object in IE9 Allowing Invalid Date
body: <p>When passing an invalid date via the constructor of a JavaScript Date() object IE9 appears to be constructing a valid Date e.g. "56 Aug 2009" returns a date object instance. Chrome by contrast, does not.</p>
  
  <p>Having read the MSDN documentation regarding the Date object in IE9 (link below) and there is a paragraph that states:</p>
  
  <blockquote>
    <p>JavaScript is fairly flexible about the date format. It allows for
    variants such as 8-24-2009, August 24, 2009, and <strong>24 Aug 2009</strong>. For more
    information, see Formatting Date and Time Strings (JavaScript).</p>
  </blockquote>
  
  <p>Above paragraph taken from: <a href="http://msdn.microsoft.com/en-us/library/ee532932%28v=vs.94%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ee532932(v=vs.94).aspx</a></p>
  
  <p>The following snippet of code is used to check whether a date is valid. It works in Chrome but not in IE9:</p>
  
  <pre><code>function validateDate(d) {
      var dt = new Date(d);
      if (Object.prototype.toString.call(dt) !== "[object Date]") return false;
  
      return !isNaN(dt.getTime());
  }
  </code></pre>
  
  <p>When running this code:</p>
  
  <pre><code>console.log(new Date("56 Aug 2009"));
  </code></pre>
  
  <p><strong>IE9 Result</strong></p>
  
  <pre><code>Fri Sep 25 00:00:00 UTC+0100 2009
  </code></pre>
  
  <p><strong>Chrome Result</strong></p>
  
  <pre><code>Invalid Date
  </code></pre>
  
  <p>Here is a JsFiddle with a more detailed example:</p>
  
  <p><a href="http://jsfiddle.net/WKMdc/8/" rel="nofollow">http://jsfiddle.net/WKMdc/8/</a></p>
  
  <p>This behaviour is unexpected (perhaps due to incorrect assumptions or maybe a bug in the validate that's going unnoticed!).</p>
  
  <p>What alternative method is there to verify a date is valid that would work in IE9 and allow the use of native browser features?</p>