在JSP里不能通过javascript的验证,而直接提交了表单
下面是register.jsp代码
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>用户注册</title>
<script language=JavaScript src="script/regcheckdata.js"></script>
</head>
<body>
<form name="form" action="register.jsp" method="get" onSubmit="return checkdata()">
<input type="hidden" name="action" value="register"/>
<table width="750" align="center" border="2">
<tr>
<th colspan="2" align="center">用户注册</th>
</tr>
<tr>
<td>用户名:</td>
<td>
<input type=text name="username" size="30" maxlength="10">
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input type=password name="password" size="15" maxlength="12">
</td>
</tr>
<tr>
<td>密码确认:</td>
<td>
<input type=password name="password2" size="15" maxlength="12">
</td>
</tr>
<tr>
<td>电话:</td>
<td>
<input type=text name="phone" size="15" maxlength="11">
</td>
</tr>
<tr>
<td>地址:</td>
<td>
<textarea rows="12" cols="80" name="addr" wrap="hard"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="提交">
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</body>
</html>
下面是regcheckdata.js代码
function checkdata() {
var ssn=form.username.value.toLowerCase();
if(!checkUserName(ssn)) return false; //用户名检查
if(strlen(form.password.value)<6) || strlen(form.password.value)>16) {
alert("\正确的登录密码长度为6-16位,仅可用英文、数字、特殊字符!")
form.password.focus()
return false;
}
if(strlen2(form.password.value)) {
alert("\您的密码中包含了非法字符,仅可用英文、数字、特殊字符!")
form.password.focus()
return false;
}
if(form.password.value == form.username.value) {
alert("\用户名与密码不能相同")
form.password.focus()
return false;
}
if(form.password2.value == "") {
alert("\请输入密码确认!")
form.password2.focus()
return false;
}
if(form.password2.value != form.password.value) {
alert("\两次密码输入不一致!")
form.password.focus();
return false;
}
if(form.phone.value == "") {
alert("\请输入电话!")
form.phone.focus()
return false;
}
if(form.addr.value == "") {
alert("\地址不能为空!")
form.addr.focus()
return false;
}
return true;
}
function che