请问各位大虾我写的这个 日期验证不好使怎么改?小弟刚学js
<html>
<head>
<script language="Javascript">
function commitCheck() {
if(!checkName()) {
return false;
} else if(!checkPasswor()){
return false;
} else if(!checkMail()){
return false;
} else if(!checkPhone()){
return false;
} else if(!isTime1()){
return false;
}
{
// submit
return true;
}
}
function checkName(){
var obj = document.getElementById("n");
var s = obj.value;
s = trim(s);
if(s.length==0){
alert("用户名不能为空");
obj.focus();
return false;
} else {
return true;
}
}
function checkPasswor(){
var obj = document.getElementById("p");
var obj2 = document.getElementById("r");
var s = obj.value;
var s2 = obj2.value;
if(s.length==0){
alert("密码不能为空");
obj.value = "";
obj2.value = "";
obj.focus();
return false;
} else if(s != s2){
alert("密码无效");
obj.value = "";
obj2.value = "";
obj.focus();
return false;
} else {
return true;
}
}
function checkMail(){
var obj = document.getElementById("m");
var s = obj.value;
s = trim(s);
var reg = /^[A-Za-z0-9_\-]+@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+$/;
if(s.length > 0 && !s.match(reg)){
alert("电子邮件无效");
obj.focus();
return false;
}else{
return true;
}
}
function checkPhone(){
var obj = document.getElementById("ph");
var s = obj.value;
s = trim(s);
var reg = /^[0-9]*$/;
if( !s.match(reg)){
alert("电话请输入数字");
obj.focus();
return false;
}
}
function isTime1(str)
{
var obj = document.getElementById("date");
var rr = obj.value;
rr = trim();
var rr=/^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$/
if(!rr.test(form.date.value))
{
alert('请输入正确的时间格式,如:2011-01-27 22:12:00');
form.date.focus();
return false;
}
alert('ok!');
return true;
}
function trim(s){
var start = 0;
var end = 0;
var leng = s.length;
var findStart = false;
var index ;
for(index=0; index<leng;index++){
if( s.charAt(index) == ' ' ) {
} else {
if(!findStart){
start = index;
findStart = true;
}
end = index + 1;
}
}
return s.substring(start,end);
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td align="right">用户名:</td>
<td align="left"><input id="n" type="text" maxLength="40"/></td>
</tr>
<tr>
<td align="right">性别:</td>
<td align="left"><input type="radio" name="sex"