【 tulaoshi.com - Javascript 】
1.校验日期
<script language=javascript
function isDate(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, r-1, r);
return (d.getFullYear()==r&&(d.getMonth()+1)==r&&d.getDate()==r);
}
alert(isDate("2002-01-31"));
alert(isDate("2002-01-41"));
</script
2.校验日期加时间<script language=javascript
function isTime(str)
{
var r = str.match(/^(d{1,4})(-|/)(d{1,2})2(d{1,2}) (d{1,2}):(d{1,2}):(d{1,2})$/);
if(r==null)return false; var d = new Date(r, r-1,r,r,r,r);
return (d.getFullYear()==r&&(d.getMonth()+1)==r&&d.getDate()==r&&d.getHours()==r&&d.getMinutes()==r&&d.getSeconds()==r);
}
alert(isTime("2002-1-31 12:34:56"));
alert(isTime("2001-2-29 12:54:56"));
alert(isTime("2002-1-41 12:00:00"));
</script