以下内容主要通过js代码给大家介绍,代码比较简单,包含注释,有好的建议欢迎提出。
如下图,当查询条件含有日期时,如“2012-3-4”,查询前校验输入的日期字符串是否为有效的日期
var snapshot_createTime_begin=$(selector+" input[name='createTime_begin']").val().trim();
var snapshot_createTime_end=$(selector +" input[name='createTime_end']").val().trim();
try{
//判断开始时间是否为有效的日期
if(snapshot_createTime_begin!=""&&new Date(snapshot_createTime_begin).getDate()!=snapshot_createTime_begin.match(/-\d{0,2}$/g)[0].replace(/-/g,"")){
throw new Error();
}
//判断结束时间是否为有效的日期
if(snapshot_createTime_end!=""&&new Date(snapshot_createTime_end).getDate()!=snapshot_createTime_end.match(/-\d{0,2}$/g)[0].replace(/-/g,"")){
throw new Error();
}
if(Date.parse(snapshot_createTime_begin)>Date.parse(snapshot_createTime_end)){
//alert("开始日期不应当超过结束日期!");
alert("开始日期不应当超过结束日期!");
return ;
}
$.extend(pageObj,{
createTimeBegin:snapshot_createTime_begin,
createTimeEnd:snapshot_createTime_end,
});
initPagination();
}catch(e){
//alert("请输入有效日期!")
alert("请输入有效日期!");
}
js判断年月日是否一个有效日期
function isdate(intYear,intMonth,intDay){
if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;
if(intMonth>12||intMonth<1) return false;
if ( intDay<1||intDay>31)return false;
if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30)) return false;
if(intMonth==2){
if(intDay>29) return false;
if((((intYear%100==0)&&(intYear%400!=0))||(intYear%4!=0))&&(intDay>28))return false;
}
return true;
}
以上代码就是对日期的有效性校验,希望对大家有所帮助。
标签:
有效日期,js日期校验
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“纯javascript判断查询日期是否为有效日期”评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
