js 判断日期是否正确

js 判断日期是否正确

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

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

js 判断日期是否正确

//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 所以沒辦法只有截取了。

還請各位大神賜教。