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("请输入有效日期!");
            }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值