判断输入框中输入的日期格式为yyyy-mm-dd和正确的日期

判断输入框中输入的日期格式为yyyy-mm-dd和正确的日期
 
function IsDate(str) {
//如果是正确的日期格式返回true,否则返回false
var regExp;
regExp = /\b\d{4}-\d{1,2}-\d{1,2}\b/;
//判断整体格式yyyy-mm-dd
if (str != str.match(/\d{4}-\d{2}-\d{2}/ig)) {
return false;
}
var tmpArr;
//tmpArr = str.split("-");
tmpArr = str.split('-');
var rYear, rMonth, rDay
rYear = parseInt(tmpArr[0]);
rMonth = parseInt(tmpArr[1]);
rDay = parseInt(tmpArr[2]);
//判断月
//if ((rMonth > 12) || (rMonth < 1)) {
// alert('月份输入错误!');
// return false;
//}
var rYearflag;
//判断润年
if (((rYear % 100) == 0) && ((rYear % 4) == 0)) {
rYearflag = true;
} else if ((rYear % 4) == 0) {
rYearflag = true;
} else {
rYearflag = false;
}
if (((",1,3,5,7,8,10,12,").indexOf("," + rMonth + ",") != -1) && (rDay < 32)) {
return (true);
} else if (((",4,6,9,11,").indexOf("," + rMonth + ",") != -1) && (rDay < 31)) {
return (true);
} else if (rDay < 29) {
return (true);
} else if (rYearflag && (rDay < 30)) {
return (true);
} else {
return false;
}
}

posted @ 2020-12-15 18:01  吃不棒的胖胖糖  阅读(711)  评论(0编辑  收藏  举报