JS的日期输入判断

var checkdate_rtn=false;//全局变量,日期检查不合法则不允许保存
function checkdate()
  {
 
   
   var datetime=document.all["signaltime"].value;
   
   var date=datetime.substring(0,8);
   var time=datetime.substring(8,14);
    var year=parseInt(datetime.substring(0,4));
   var month=(datetime.substring(4,6));
   var day=(datetime.substring(6,8));
   var hour=(datetime.substring(8,10));
   var min=(datetime.substring(10,12));
   var sec=(datetime.substring(12,14));
 if(datetime.length==14)//表示输入的日期长度要为14
    {
  
        if(year>1900&&year<2099)
        {
          if(month<13)
          {
                      
             if(hour<24 && min<60 && sec<60)
             {
               if(month==01||month==03||month==05||month==07||month==08||month==10||month==12)
               { 
                if(day<32)
                
                { 
               
                 checkdate_rtn=true;
                }
               }
               if(month==02&&(day<30&&year%4==0)||(day<29&&year%4!=0))
                {
                 checkdate_rtn=true;
                }
               if(month==04||month==06||month==09||month==11)
                {
                 checkdate_rtn=true;
                }

             }
          
            }
          }
    }
  } 

posted on 2007-08-07 18:36 刘铮 阅读(332) 评论(0)  编辑  收藏 所属分类: JavaScript


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

留言簿(1)

文章分类(141)

文章档案(147)

搜索

最新评论