zoukankan      html  css  js  c++  java
  • js日期格式验证

    js日期格式验证

    <input type="text" maxLength='10' onkeyup='checkDate(this.value,jQuery(this));' onafterpaste='checkDate(this.value,jQuery(this))' onblur='blurdate(this.value,jQuery(this))'>
    function checkDate(date,a){
        if(date.length==10){
            var reg = /^(d{1,4})(-)(d{1,2})2(d{1,2})$/;
            var r = date.match(reg);
            if(r==null){
            //不符合YYYY-MM-DD格式 swal({ title:
    "您输入的日期格式不正确!", timer: 1300, type:"warning", showConfirmButton: false }); a.val("") }else{
            //除去不正确时间如1234-45-56
    var d = new Date(r[1], r[3] - 1, r[4]); var c=(d.getFullYear() == r[1] && (d.getMonth() + 1) == re[3] && d.getDate() == r[4]); if(!c){ swal({ title: "请输入正确的日期!", timer: 1300, type:"warning", showConfirmButton: false }); a.val(""); } } } }
    function blurdate(date,a){
        if(date!=""){
           if(date.length<10){
                swal({
                        title: "您输入的日期格式不正确!",
                        timer: 1300,
                        type:"warning",
                        showConfirmButton: false
                    });
                a.val("")
                a.parent().parent().find("input[type=hidden]").val("");
            }
        }
    }
  • 相关阅读:
    Bluetooth GATT介绍
    Bluetooth ATT介绍
    Bluetooth GAP介绍
    Bluetooth Low Energy介绍
    CC2540介绍
    DBus介绍
    802.11 MAC层
    802.11介绍
    Python资料
    Bluedroid之GKI
  • 原文地址:https://www.cnblogs.com/web520/p/7994169.html
Copyright © 2011-2022 走看看