zoukankan      html  css  js  c++  java
  • 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("请输入有效日期!");
                }


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    第九周进度条
    梦断代码阅读笔记01
    NABCD分析
    软件工程个人作业05
    HDU 3949 XOR(线性基)
    luogu 2115 破坏(01分数规划)
    luogu 1360 阵容均衡(前缀和+差分+hash)
    luogu 1967 货车运输(最大生成树+LCA)
    luogu 1344 追查坏牛奶(最小割)
    BZOJ 2007 海拔(平面图最小割转对偶图最短路)
  • 原文地址:https://www.cnblogs.com/wlf-919874006/p/4811305.html
Copyright © 2011-2022 走看看