为什么不能检测username的长度?
代码如下:
原意如下,让javavscript函数去验证表单输入的正确性,
但
if ((theform.username.value.length > 16) && (theform.username.value.length < 3))
{
alert("字符越界。");
return false;
}
这一段总是不能执行!
那位大侠不吝赐教
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> aaa</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK rel="stylesheet" type="text/css" href="xxxxxxxxxx.css">
</HEAD>
<BODY><script language="javascript">
function validate(theform) {
if (theform.username.value=="" && theform.password.value=="")
{
alert("用户名和密码项不能为空!");
return false;
}
if (theform.username.value=="")
{
alert("请输入用户名!");
return false;
}
if (theform.password.value=="")
{
alert("请输入密码!");
return false;
}
if ((theform.username.value.length > 16) && (theform.username.value.length < 3))
{
alert("字符越界。");
return false;
}
//判断用户名的长度和密码的长度。
}
</script>
<form method="POST" name="vbform" onSubmit="return validate(this)" action="admin/login_form_output.php">
<table border="1" width="64%">
<tr>
<td width="42%">
<p align="right">用户名</p>
</td>
<td width="58%"><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td width="42%">
<p align="right">密码</p>
</td>
<td width="58%"><input type="password" name="password" size="20"></td>
</tr>
</table>
<p><input type="submit" value="提交" name="submit"><input type="reset" value="重置" name="reset"></p>
</form>
</body>
</html>