js判断 yyy-mm-dd的时间格式正确与否,网上很多,但是怎么验证
yyyy-mm-dd hh:MM:ss的正确?
比如 2007-10-09 12:20:00

<input name="haha" onblur="check(this)">
<script language=javascript>
function check(obj)
{
if(!checkDate(obj)){
alert("输入错误")
}
else{
alert("输入正确")
}
}
function checkDate(obj)
{
var str=obj.value
if(str=="")return true
re=/^(d{4})-(d{2})-(d{2})s(d{2}):(d{2}):(d{2})$/
if(!re.test(str))
return false
var strYear=RegExp.$1
var strMonth=parseInt(RegExp.$2,10)-1
var strDate=parseInt(RegExp.$3,10)
var strHour=parseInt(RegExp.$4,10)
var strMinute=parseInt(RegExp.$5,10)
var strSecond=parseInt(RegExp.$6,10)
var tempDate=new Date(strYear,strMonth,strDate,strHour,strMinute,strSecond)
return (tempDate.getFullYear()==strYear)&&(tempDate.getMonth()==strMonth)&&(tempDate.getDate()==strDate)&&(tempDate.getHours()==strHour)&&(tempDate.getMinutes()==strMinute)&&(tempDate.getSeconds()==strSecond);
}
</script>
yyyy-mm-dd hh:MM:ss的正确?
比如 2007-10-09 12:20:00

<input name="haha" onblur="check(this)">


























