判断日期是否正确?
以下函数在判断录入的日期数据是否正确时,在录入其它月份时没有问题,不知道为什么在录入8月份和9月份时,例如:2009-8-32或者2009-9-32时不能返回true,请高手帮忙看一下,谢谢!
//检查判断输入的日期格式是否正确//
function CheckDate(INDate){
if (INDate==""){return true;}
//转换年份//
subYY = INDate.substr(0,4);
if(isNaN(subYY) || subYY<=0){return true;}
//转换月份//
if(INDate.indexOf('-',0)!=-1){separate="-"}
else{
if(INDate.indexOf('/',0)!=-1){separate="/"}
else {return true;}
}
area=INDate.indexOf(separate,0)
subMM=INDate.substr(area+1,INDate.indexOf(separate,area+1)-(area+1))
if(isNaN(subMM) || subMM<=0){
return true;
}
if(subMM.length<2){subMM="0"+subMM}
//转换日//
area=INDate.lastIndexOf(separate)
subDD=INDate.substr(area+1,INDate.length-area-1)
if(isNaN(subDD) || subDD<=0){
return true;
}
if(eval(subDD)<10){subDD="0"+eval(subDD)}
NewDate=subYY+"-"+subMM+"-"+subDD
if(NewDate.length!=10){return true;}
if(NewDate.substr(4,1)!="-"){return true;}
if(NewDate.substr(7,1)!="-"){return true;}
var MM=NewDate.substr(5,2);
var DD=NewDate.substr(8,2);
if(parseInt(MM)>12){return true;}//月份大于12
if((subYY%4==0 && subYY%100!=0)||subYY%400==0){ //判断是否为闰年
if(parseInt(MM)==2){
if(DD>29){return true;}
}
}else{
if(parseInt(MM)==2){
if(DD>28){return true;}
}
}
//根据月份判断最大天数
if(parseInt(MM)==1){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==3){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==5){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==7){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==8){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==10){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==12){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==2){if(parseInt(DD)>30){return true;}}
if(parseInt(MM)==4){if(parseInt(DD)>30){return true;}}
if(parseInt(MM)==6){if(parseInt(DD)>30){return true;}}
if(parseInt(MM)==9){if(parseInt(DD)>30){return true;}}
if(parseInt(MM)==11){if(parseInt(DD)>30){return true;}}
//以上判断完毕后返回false值
return false;
}
//检查判断输入的日期格式是否正确//
function CheckDate(INDate){
if (INDate==""){return true;}
//转换年份//
subYY = INDate.substr(0,4);
if(isNaN(subYY) || subYY<=0){return true;}
//转换月份//
if(INDate.indexOf('-',0)!=-1){separate="-"}
else{
if(INDate.indexOf('/',0)!=-1){separate="/"}
else {return true;}
}
area=INDate.indexOf(separate,0)
subMM=INDate.substr(area+1,INDate.indexOf(separate,area+1)-(area+1))
if(isNaN(subMM) || subMM<=0){
return true;
}
if(subMM.length<2){subMM="0"+subMM}
//转换日//
area=INDate.lastIndexOf(separate)
subDD=INDate.substr(area+1,INDate.length-area-1)
if(isNaN(subDD) || subDD<=0){
return true;
}
if(eval(subDD)<10){subDD="0"+eval(subDD)}
NewDate=subYY+"-"+subMM+"-"+subDD
if(NewDate.length!=10){return true;}
if(NewDate.substr(4,1)!="-"){return true;}
if(NewDate.substr(7,1)!="-"){return true;}
var MM=NewDate.substr(5,2);
var DD=NewDate.substr(8,2);
if(parseInt(MM)>12){return true;}//月份大于12
if((subYY%4==0 && subYY%100!=0)||subYY%400==0){ //判断是否为闰年
if(parseInt(MM)==2){
if(DD>29){return true;}
}
}else{
if(parseInt(MM)==2){
if(DD>28){return true;}
}
}
//根据月份判断最大天数
if(parseInt(MM)==1){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==3){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==5){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==7){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==8){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==10){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==12){if(parseInt(DD)>31){return true;}}
if(parseInt(MM)==2){if(parseInt(DD)>30){return true;}}
if(parseInt(MM)==4){if(parseInt(DD)>30){return true;}}
if(parseInt(MM)==6){if(parseInt(DD)>30){return true;}}
if(parseInt(MM)==9){if(parseInt(DD)>30){return true;}}
if(parseInt(MM)==11){if(parseInt(DD)>30){return true;}}
//以上判断完毕后返回false值
return false;
}
...全文
相关推荐
Java正则判断日期格式是否正确的方法示例
Java正则判断日期格式是否正确的方法示例Java正则判断日期格式是否正确的方法示例主要介绍了Java正则判断日期格式是否正确的方法,结合实例形式分析了Java针对日期字符串正则判断的相关操作技巧。
C#正则表达式判断输入日期格式是否正确
在软件开发过程中,日期和时间的验证是一个常见的需求,尤其在处理用户输入或者外部数据源时。本文介绍的是如何使用C#编程语言和正则表达式来判断输入日期格式是否正确。
java获取昨天日期字符串的方法
通过`getDaysInMonth`方法,我们可以根据年份和月份判断该月有多少天,而`isLeapYear`方法则用来检查是否是闰年。
javascript 日期常用的方法
日期的换算比较在实际应用中,我们常常需要比较两个日期的大小,比如判断用户的注册日期是否早于某个特定的时间点等。
导出word文档日期问题.docx
== "error"> xxx</#if>`分别用于判断字符串是否等于或不等于指定值。3. **判断List长度**:如果需要检查一个List的长度是否大于0,可以使用`<#if (fields?


