看看下面的
http://www.changshainvest.gov.cn/myblog/blogview.asp?logID=52&cateID=5

解决方案 »

  1.   

    //验证日期
    function ValidateDate()
    {

    var reg=/^(\d{4})(\/|-)(\d{1,2})\2(\d{1,2})$/;
    var arr=document.RegExpDemo.txtDate.value.match(reg)
    if(arr==null)
    {
    window.alert("错误的时间格式,请按格式填写\n 如: 1999/10/25 或 1999-10-25");
    document.RegExpDemo.txtDate.select();
    document.RegExpDemo.txtDate.focus();
    return false;
    }

    var tempDate=new Date(arr[1],arr[3]-1,arr[4]);
    if((tempDate.getFullYear()==arr[1]&&(tempDate.getMonth()+1)==arr[3]&&tempDate.getDate()==arr[4])==false)
    {
    window.alert("错误的时间格式,请按格式填写\n 如: 1999/10/25 或 1999-10-25");
    document.RegExpDemo.txtDate.select();
    document.RegExpDemo.txtDate.focus();
    return false;
    }
    window.alert(document.RegExpDemo.txtDate.value);
    return true;

    }