2.2 短日期,形如 (2003-12-05)
function strDateTime(str)
      {
         var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
         if(r==null)return false; 
         var d= new Date(r[1], r[3]-1, r[4]); 
         return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
      }
      ^(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29))$)|(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))$Description:   This expression validates dates in the y/m/d format from 1600/1/1 - 9999/12/31. Follows the same validation rules for dates as my other date validator (m/d/y format) located in this library.  
Matches:  [04/2/29], [2002-4-30], [02.10.31]  [ More Details]  
Non-Matches:  [2003/2/29], [02.4.31], [00/00/00]    2.3 长时间,形如 (2003-12-05 13:04:06)
function strDateTime(str)
      {
        var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/; 
        var r = str.match(reg); 
        if(r==null)return false; 
        var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]); 
        return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
      }

解决方案 »

  1.   

    javascrpt
    function validateTime ( strValue ) {
      var objRegExp = /^([1-9]|1[0-9]|2[0-3]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/;  return objRegExp.test( strValue );}
    function validateCNDate( strValue ) {
      var objRegExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/  //check to see if in correct format
      if(!objRegExp.test(strValue))
        return false; //doesn't match pattern, bad date
      else{
        var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year
            var intDay = parseInt(arrayDate[2],10);
            var intYear = parseInt(arrayDate[0],10);
        var intMonth = parseInt(arrayDate[1],10);        //check for valid month
            if(intMonth > 12 || intMonth < 1) {
                    return false;
            }    //create a lookup for months not equal to Feb.
        var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,
                            '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31}    //check if month value and day value agree
        if(arrayLookup[parseInt(arrayDate[1])] != null) {
          if(intDay <= arrayLookup[parseInt(arrayDate[1])] && intDay != 0)
            return true; //found in lookup table, good date
        }    //check for February
       if (intMonth-2 ==0) {
            var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
        if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
          return true; //Feb. had valid number of days
      }
      }
      return false; //any other values, bad date
    }
    vbscript
    isdate()建议用vbscript