HTML的内置判断函数为什么没有执行?
如题。输入非法数据为什么不报错呢?
<html>
<head>
<title>register info</title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
</head>
<script>
function check(){
username=document.form1.value;
pwd1=document.form1.pwd1.value;
pwd2=document.form1.pwd2.value;
year=document.form1.year.value;
month=document.form1.month.value;
day=document.form1.day.value;
email=document.form1.email.value;
interest=document.form1.interest.value;
if(username.length<6||username.length>15){
alert("usename must be 5-15char");
return false;
}
if(pwd1!=pwd2){
alert("password is not correct!");
return false;
}
if(year.lenth!=4||month>13||month<1||day>32||day<1{
alert("birthday is incorrect!")
return false;
}
if(email=""||(email.indexof('@'==-1)||(email.indexof('.')==-1)){
alert("email format is incorrect!")
return false;
}
return true;
}
</script>
<body bgcolor="#FFFFFF" text="#000000">
<p align="center">input register info</p>
<form name="form1" method="post" action="register.jsp" OnSubmit="return check();">
<table width="36%" border="1" cellspacing="1" cellpadding="1"
align="center" height="160">
<tr>
<td width="45%">username(6-15)bit</td>
<td width="55%">
<input type="text" name="username" size="15">
</td>
</tr>
<tr>
<td width="45%">password(6-10)bit</td>
<td width="55%">
<input type="password" name ="pwd1" size="10">
</td>
</tr>
<tr>
<td width="45%">password confirm</td>
<td width="55%">
<input type="password" name ="pwd2" size="10">
</td>
</tr>
<tr>
<td width="45%">birth day</td>
<td width="55%">
<input type="text" name ="year" size="4">
year
<input type="text" name ="month" size="2">
month
<input type="text" name ="day" size="2">
day</td>
</tr>
<tr>
<td width="45%">sex</td>
<td width="55%">
<input type="radio" name ="gender" value="man" selected>
man
<input type="radio" name ="gender" value="woman">
woman
</td>
</tr>
<tr>
<td width="45%">email</td>
<td width="55%">
<input type="text" name ="email" size="20">
</td>
</tr>
<tr>
<td width="45%">interest</td>
<td width="55%">
<input type="text" name ="interest" size="20">
</td>
</tr>
</table>
<p align="center">
<input type="submit" name="Submit" value="tijiao">
<input type="reset" name="Submit2" value="chongzhi">
</p>
</form>
<p> </p>
<p> </p>
</body>
</html>
<html>
<head>
<title>register info</title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
</head>
<script>
function check(){
username=document.form1.value;
pwd1=document.form1.pwd1.value;
pwd2=document.form1.pwd2.value;
year=document.form1.year.value;
month=document.form1.month.value;
day=document.form1.day.value;
email=document.form1.email.value;
interest=document.form1.interest.value;
if(email===""
[解决办法]
username.length<6
[解决办法]
username.length>15){
alert("usename must be 5-15char");
return false;
}
if(pwd1!=pwd2){
alert("password is not correct!");
return false;
}
if(year.lenth!=4
[解决办法]
month>13
[解决办法]
month<1
------解决方案--------------------
day>32
[解决办法]
day<1){
alert("birthday is incorrect!");
return false;
}
if(email===""
[解决办法]
(email.indexof('@'==-1)
[解决办法]
(email.indexof('.')==-1))){
alert("email format is incorrect!");
return false;
}
return true;
}
</script>
<body bgcolor="#FFFFFF" text="#000000">
<p align="center">input register info</p>
<form name="form1" method="post" action="register.jsp" OnSubmit="return check();">
<table width="36%" border="1" cellspacing="1" cellpadding="1"
align="center" height="160">
<tr>
<td width="45%">username(6-15)bit</td>
<td width="55%">
<input type="text" name="username" size="15">
</td>
</tr>
<tr>
<td width="45%">password(6-10)bit</td>
<td width="55%">
<input type="password" name ="pwd1" size="10">
</td>
</tr>
<tr>
<td width="45%">password confirm</td>
<td width="55%">
<input type="password" name ="pwd2" size="10">
</td>
</tr>
<tr>
<td width="45%">birth day</td>
<td width="55%">
<input type="text" name ="year" size="4">
year
<input type="text" name ="month" size="2">
month
<input type="text" name ="day" size="2">
day</td>
</tr>
<tr>
<td width="45%">sex</td>
<td width="55%">
<input type="radio" name ="gender" value="man" selected>
man
<input type="radio" name ="gender" value="woman">
woman
</td>
</tr>
<tr>
<td width="45%">email</td>
<td width="55%">
<input type="text" name ="email" size="20">
</td>
</tr>
<tr>
<td width="45%">interest</td>
<td width="55%">
<input type="text" name ="interest" size="20">
</td>
</tr>
</table>
<p align="center">
<input type="submit" name="Submit" value="tijiao">
<input type="reset" name="Submit2" value="chongzhi">
</p>
</form>
<p> </p>
<p> </p>
</body>
</html>