// 日期 function isDate(date) { date = $.trim(date); var I = /^(d{4})-(d{2})-(d{2})$/; I.exec(date); if (!I.test(date) && RegExp.$2 <= 12 && RegExp.$3 <= 31) { return false; } var year, month, day; year = parseInt(date.split("-")[0], 10); month = parseInt(date.split("-")[1], 10); day = parseInt(date.split("-")[2], 10); if (! ((1 <= month) && (12 >= month) && (31 >= day) && (1 <= day))) { return false; } if ((month <= 7) && ((month % 2) == 0) && (day >= 31)) { return false; } if ((month >= 8) && ((month % 2) == 1) && (day >= 31)) { return false; } if (month == 2) { if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) { if (day > 29) { return false; } } else { if (day > 28) { return false; } } } return true; }
加入闰年平年的日期正则校验
^((((1[6-9]|[2-9]d)d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]d|3[01]))|(((1[6-9]|[2-9]d)d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]d|30))|(((1[6-9]|[2-9]d)d{2})-0?2-(0?[1-9]|1d|2[0-8]))|(((1[6-9]|[2-9]d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$
日期js比较可以直接用>,<,==('2012-12-13>2012-12-14',结果返回false)