Validate number of days in a given month
<p>Performance is of the utmost importance on this one guys... This thing needs to be lightning fast!
<br />
<br />
<br />
How would you validate the number of days in a given month?</p>

<p>My first thought was to make an array containing the days of a given month, with the index representing the month:</p>

<pre><code>var daysInMonth = [
    31, // January
    28, // February
    31, // March
    etc.
];
</code></pre>

<p>And then do something along the lines of:</p>

<pre><code>function validateDaysInMonth(days, month)
{
    if (days &lt; 1 || days &gt; daysInMonth[month]) throw new Error("Frack!");
}
</code></pre>

<p>But... What about leap years? How can I implement checking for leap years and keep the function running relatively fast?
<br />
<br />
<br />
<strong>Update:</strong> I'd like you guys to show me some code which does the days in month- leap year validation.</p>

<p>Here's the flowchart describing the logic used today:</p>

<p><img src="http://visualbasic.about.com/library/graphics/dykleapyr1-1.gif" /></p>
