js 验证日期的有效性,合法性(并非格式)
function IsDate(str) {
arr = str.split("-");
if (arr.length == 3) {
intYear = parseInt(arr[0], 10);
intMonth = parseInt(arr[1], 10);
intDay = parseInt(arr[2], 10);
if (isNaN(intYear) || isNaN(intMonth) || isNaN(intDay)) {
return false;
}
if (intYear > 2100 || intYear < 1900 || intMonth > 12 || intMonth < 0 || intDay > 31 || intDay < 0) {
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && intDay > 30) {
return false;
}
if (intYear % 100 == 0 && intYear % 400 || intYear % 100 && intYear % 4 == 0) {
if (intDay >
29) return false;
} else {
if (intDay > 28) return false;
}
return true;
}
return false;
}