选择
http://www.51windows.net/myfile/js/date_today.htm
http://www.51windows.net/hw/asp/jsview.asp?id=240

解决方案 »

  1.   

    function checkdate(checkDate){
      //设置日期格式:yyyy-mm-dd,其中yyyy[0000-9999]、mm[1-12]、dd[01-31]
      var re;
      re = /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])$/;
      //日期不能为空
      if(checkDate.length == 0){
        alert("系统提示:日期不能为空!");
        return false;
      }
      //验证格式
      if(!re.test(checkDate)){
        alert("系统提示:日期格式非法或错误日期!");
        return false;
      }
      //验证当前的年月日是否存在
      var yyyy = checkDate.substr(0,4);
      var mm   = checkDate.substr(5,2);
      var dd   = checkDate.substr(8,2);
      var high;
      //增加的代码
      mm = parseInt(mm);
      //增加的代码  switch (mm){
        case  2: 
     high = 28;
                 if ((yyyy % 400 == 0) || ((yyyy % 4 == 0) && (yyyy % 100 != 0))){
                   high = 29;
                 }
                 break;
        case  1:
        case  3:
        case  5:
        case  7:
        case  8:
        case 10:
        case 12: high = 31;
                 break;
        default: high = 30;
                 break;
      }
      if(dd > high){
        alert("非法日期:\n" + yyyy + "年" + mm + "月没有第" + dd + "天!");
        return false;
      }
      return true;
    }
      

  2.   

    mm = parseInt(mm);改为:mm = parseInt(mm,10);