zoukankan      html  css  js  c++  java
  • javascript验证日期的函数

    //判断日期是否合法
    function IsDate(oTextbox) {
        var regex = new RegExp("^(?:(?:([0-9]{4}(-|\/)(?:(?:0?[1,3-9]|1[0-2])(-|\/)(?:29|30)|((?:0?[13578]|1[02])(-|\/)31)))|([0-9]{4}(-|\/)(?:0?[1-9]|1[0-2])(-|\/)(?:0?[1-9]|1\\d|2[0-8]))|(((?:(\\d\\d(?:0[48]|[2468][048]|[13579][26]))|(?:0[48]00|[2468][048]00|[13579][26]00))(-|\/)0?2(-|\/)29))))$");
        var dateValue = oTextbox.value;
        if (!regex.test(dateValue)) {
            alert("日期有误!");
            dateValue = "";
            this.focus();
            return;
        }
    }
    
    
    使用测试
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title></title>
        <script type="text/javascript" src="jQuery/JScript1.js"></script>
        <script type="text/javascript" src="jQuery/jquery-vsdoc.js"></script>
    </head>
    <body>
    <input type="text" id="sDate" />
    <script type="text/javascript">
        $("#sDate").blur(function() {IsDate($(this)[0]);})
    </script>
    </body>
    </html>
    
    
  • 相关阅读:
    #与javascript:void(0)的区别
    单选框、复选框、下拉列表
    数据类型后的“?”
    c#中日期的处理
    日期控件html
    javascript获取后台传来的json
    Hashtable语法简介
    Hashtable(哈希表)
    Dictionary 字典
    远程SQL Server连接不上
  • 原文地址:https://www.cnblogs.com/lyz8/p/1691119.html
Copyright © 2011-2022 走看看