function isDate(){
var date = document.getElementById("pcDate").value;
var result = date.match(/((^((1[8-9]d{2})|([2-9]d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]d{2})|([2-9]d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]d{2})|([2-9]d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/);
if(result==null)
{
alert("请输入正确的日期格式");
return false;
}
}
</script>
<form action="" method="post" onsubmit="return isDate()">
</form>
当日期格式不正确,不为eg:2001-09-01例如这样的例子, 并且判断日期是否符合规范:2001-90-21(错误) 就会返回错误,然后就会阻止submit()提交;