作者在 2010-11-09 10:52:56 发布以下内容
function validateDate(date) {
var pos1 = date.indexOf("-");
var pos2 = date.indexOf("-", pos1 + 1);
if ( pos1 == -1 || pos2 == -1 ) {
return false;
}
var year = date.substr(0, pos1);
var month = date.substr(0, pos1);
var day = date.substr(0, pos1);
if ( month < 1 || month > 12 ) {
return false;
}
if ( day < 1 || day > 31 ) {
return false;
}
if ( (month == 4 || month == 6 || month == 11) && (day == 31) ) {
return false;
}
if ( month == 2 ) {
var leap = (year % 4 == 0 && (year %100 != 0 || year % 400 == 0));
if (day > 29 || (day == 29 && !leap)) {
return false;
}
}
return true;
}
var pos1 = date.indexOf("-");
var pos2 = date.indexOf("-", pos1 + 1);
if ( pos1 == -1 || pos2 == -1 ) {
return false;
}
var year = date.substr(0, pos1);
var month = date.substr(0, pos1);
var day = date.substr(0, pos1);
if ( month < 1 || month > 12 ) {
return false;
}
if ( day < 1 || day > 31 ) {
return false;
}
if ( (month == 4 || month == 6 || month == 11) && (day == 31) ) {
return false;
}
if ( month == 2 ) {
var leap = (year % 4 == 0 && (year %100 != 0 || year % 400 == 0));
if (day > 29 || (day == 29 && !leap)) {
return false;
}
}
return true;
}