js 判断日期是否正确

  写了一个js function  在这里跟大伙分享一下

我们项目 是这样的 年份和月份是selectBox类型 Day是TextBox类型 所以只需要判断 Day 输入是否合理就行

//create by Elvin 2013-12-10
    function checkDay(dayCp,dayId,monthId,yearId)
      {
      var day=getValue(dayId);
      var month=getValue(monthId);
      var year=getValue(yearId);
      var strP =/^\d+$/;
      var oNumValue = getValue(dayId);
      if (!oNumValue) {
          return;
      }
      if(!strP.test(oNumValue))
      {
          fsAlert('expectedformats|' + dayCp + '|99');
          document.getElementById(dayId).focus();          
      }
      var dayInt=parseInt(day);
      if(month=="09")
      {
      month=month.substr(1,1);
      }
      var monthInt=parseInt(month);
      var yearInt=parseInt(year);
      if ((monthInt == 4) || (monthInt == 6) || (monthInt == 9) || (monthInt == 11)) {
          if (dayInt > 30) {
              fsAlert('expectedformats|' + dayCp + '|1-30');
              document.getElementById(dayId).focus();
          }
      } else if (monthInt == 2) {
          if ((yearInt % 4 == 0 && yearInt % 100 != 0) || (yearInt % 400 == 0)) {
              if (dayInt > 29) {
                  fsAlert('expectedformats|' + dayCp + '|1-29');
                  document.getElementById(dayId).focus();
              }
          } else {
              if (dayInt > 28) {
                  fsAlert('expectedformats|' + dayCp + '|1-28');
                  document.getElementById(dayId).focus();
              }
          }
      } else {
      if (dayInt > 31) {
          fsAlert('expectedformats|' + dayCp + '|1-31');
          document.getElementById(dayId).focus();
      }
      }
        
      
      }

 

if(month=="09")  這裡 爲什麽要month=month.substr(1,1);呢 其實我也特別納悶  但是但我選擇09 的時候 他parseInt之後 依然是09 所以沒辦法只有截取了。

還請各位大神賜教。

转载于:https://www.cnblogs.com/longshaokun/p/3469368.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值