Loved James' answer. Reformatted slightly for those interested.
function getDaysInMonth(m, y)
{
// months in JavaScript start at 0 so decrement by 1 e.g. 11 = Dec
--m;
// if month is Sept, Apr, Jun, Nov return 30 days
if( /8|3|5|10/.test( m ) ) return 30;
// if month is not Feb return 31 days
if( m != 1 ) return 31;
// To get this far month must be Feb ( 1 )
// if the year is a leap year then Feb has 29 days
if( ( y % 4 == 0 && y % 100 != 0 ) || y % 400 == 0 ) return 29;
// Not a leap year. Feb has 28 days.
return 28;
}
Fiddle here