<input title="日期格式: 2003-09-22" onblur="if(strDateTime(value))alert('你的日期不对')">
<script language=javascript>
function strDateTime(str)
{
   if(str=="") return false;
   var r = str.match(/^(\d{4})(-)(\d{2})\2(\d{2})$/); 
   if(r==null)return true; 
   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]);
}
</script>

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1490/1490929.xml?temp=.10664
      

  2.   

    //判断客户端输入的年、月、日是否合法,方法2
    function CheckIsDate(value)//格式为yyyy-mm-dd
    {
    var strValue  = new String();

    var year = new String();
    var month = new String();
    var day = new String();
    strValue = value;

    if (strValue.length!=10)

    return false;
    }  
    else 
    if (strValue.charAt(4)!='-'||strValue.charAt(7)!='-')
    {
    return false;
    }
    else

    year = strValue.substr(0,4);
    month = strValue.substr(5,2);
    month = month-1; 
    day = strValue.substr(8,2);

    var testDate = new Date(year,month,day)
    //alert(testDate);
    return  (year == testDate.getFullYear()) && (month ==testDate.getMonth())&&(day == testDate.getDate());
    }   
      return true;
    }
    alert(CheckIsDate("2002-04-31"));
    </script>