<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>无标题文档</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<script type="text/javascript">
function checkForm() {
var username = document.getElementById("username");
var uTip = document.getElementById("uTip");
var uRegex = /^[a-zA-Z_][a-zA-z0-9_]{5,15}$/;//正则表达式
var password = document.getElementById("password");
var pTip = document.getElementById("pTip");
var pRegex = /^[a-zA-z0-9_]{6,16}$/;
var repassword = document.getElementById("repassword");
var repTip = document.getElementById("repTip");
var sex = document.getElementsByName("sex");
var sTip = document.getElementById("sTip");
var hobby = document.getElementsByName("hobby");
var hTip = document.getElementById("hTip");
if (username.value.length == 0) {
uTip.innerHTML = "<font color='red'size='2'>用户名不能为空!</font>";
username.focus();
return false;
} else if (!uRegex.test(username.value)) {
username.value = "";
username.focus();
uTip.innerHTML = "<font color='red'size='2'>有字母数字下划线组成的6-16位,0-9不能开头!</font>";
return false;
}
if (!password.value) {
pTip.innerHTML = "<font color='red'size='2'>密码不能为空!</font>";
password.focus();
return false;
} else if (!pRegex.test(password.value)) {
password.value = "";
password.focus();
pTip.innerHTML = "<font color='red'size='2'>请输入的6-16位字符!</font>";
return false;
}
if (password.value != repassword.value) {
password.value = "";
repassword.value = "";
password.focus();
repTip.innerHTML = "<font color='red'size='2'>密码和确认密码不一致!</font>";
return false;
}
if (sex[0].checked == false && sex[1].checked == false) {
sTip.innerHTML = "<font color='red'size='2'>请选择性别!</font>";
return false;
}
var j = 0;
for (var i = 0; i < hobby.length; i++) {
if (hobby[i].checked == true) {
j++;
}
}
if (j == 0) {
hTip.innerHTML = "<font color='red'size='2'>请至少选择一个爱好!</font>";
return false;
}
}
</script>
</head>
<body>
<fieldset>
<legend>用户注册</legend>
<form action="registerAction. jsp" method="get"
οnsubmit="return checkForm();">
<table border="1" bordercolor="blue" align="center" width="550px">
<tr>
<th colspan="2"><font face="仿宋" size="6" color="blue">用户注册</font></th>
</tr>
<tr>
<td>用户名:</td>
<td><input type="text" name="username" id="username" /> <span
id="uTip"><font color="green" size="2">有字母数字下划线组成的6-16位,0-9不能开头!</font></span>
</td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password" id="password">
<span id="pTip"><font color="green" size="2">6-16位字符组成</font></span></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type="password" name="repassword" id="repassword">
<span id="repTip"><font color="green" size="2">6-16位字符组成</font></span></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女">女 <span id="sTip">
<font color="green" size="2">请选择性别!</font></span></td>
</tr>
<tr>
<td>爱好:</td>
<td><input type="checkbox" name="hobby" value="网游">网游
<input type="checkbox" name="hobby" value="看书">看书
<input type="checkbox" name="hobby" value="听音乐">听音乐
<input type="checkbox" name="hobby" value="睡觉">睡觉
<span id="hTip"><font color="green" size="2">至少选择一个爱好!</font></span></td>
</tr>
<tr>
<td>学历:</td>
<td><select name="graduation" id="graduation">
<option value="小学">小学</option>
<option value="初中">初中</option>
<option value="高中" selected="selected">高中</option>
<option value="专科">专科</option>
<option value="本科">本科</option>
<option value="研究生">研究生</option>
</select></td>
</tr>
<tr>
<td>备注:</td>
<td><textarea rows="5" cols="50">请写备注</textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="注册">
<input type="reset" value="重置"></td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>