<!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=utf-8" />
<script type="text/javascript" src="15_doctool.js"></script>
<style type="text/css">
table{
border:#39F 1px solid;
width:600px;
border-collapse:collapse;
}
table td,table th{
border:#39F 1px solid;
padding:10px;
}
table td{
background-color:#FF9;
}
table th{
background-color:#FC6;
}
#repswspan{
margin-left:120px;
}
.errorinfo{
color:#F00;
display:none ;
}
.focus{
border:#0CF 2px solid;
}
.norm{
border:#333 2px thin;
}
.error{
border:#F00 2px solid;
}
</style>
<script type="text/javascript" >
function inputColor(input)
{
input.className = "norm";
input.onfocus = function()
{
this.className="focus";
}
}
window.onload = function(){
with(document.forms[0])
{
inputColor(user);
inputColor(psw);
inputColor(repsw);
inputColor(mail);
}
}
function check(inputNode,regex,divId)
{
var b = false;
var div = byId(divId);
if(regex.test(inputNode.value))
{
inputNode.className = "norm";
div.style.display = "none";
b = true;
}
else
{
inputNode.className = "error";
div.style.display = "block";
}
return b;
}
function checkUser(userNode)
{
var regex = /^w{3,5}$/;
return check(userNode,regex,"userdiv");
}
function checkPsw(pswNode)
{
var regex = /^[a-z0-9]{3,5}$/i;
return check(pswNode,regex,"pswdiv");
}
function checkRepsw(repswNode)
{
var b = false;
var value1 = repswNode.value;
var value2 = byName("psw")[0].value;
var div = byId("repswdiv");
if(value1 == value2)
{
repswNode.className = "norm";
div.style.display = "none";
b = true;
}
else
{
repswNode.className = "error";
div.style.display = "block";
}
return b;
}
function checkMail(mailNode)
{
var regex = /^w+@w+(.w+)+$/ ;
return check(mailNode,regex,"maildiv");
}
function checkForm(formNode)
{
with(formNode)
{
if(checkUser(user) && checkPsw(psw) && checkRepsw(repsw) && checkMail(mail))
event.returnValue = true;
else
event.returnValue = false;
}
}
</script>
<title>注册表单</title>
</head>
<body>
<form onsubmit="checkForm(this)">
<table>
<tr>
<th>注册表单</th>
</tr>
<tr>
<td>
<div>用户名</div>
<div><input type="text" name="user" onblur="checkUser(this)"/></div>
<div id="userdiv" class="errorinfo">用户名错误,请按要求输入</div>
<div>提示:用户名必须是3-5位,由字母(a-z),数字(0-9),下划线(_)组成</div>
</td>
</tr>
<tr>
<td>
<div><span id="pswspan">密码</span> <span id="repswspan">确认密码</span></div>
<div>
<input type="password" name="psw" onblur="checkPsw(this)"/>
<input type="password" name="repsw" onblur="checkRepsw(this)"/>
</div>
<div class="errorinfo" id="pswdiv">密码格式错误,请按规范输入</div>
<div class="errorinfo" id="repswdiv">两次密码输入不一致</div>
<div>提示:密码必须是3-5位,由字母(a-z),数字(0-9)组成</div>
</td>
</tr>
<tr>
<td>
<div>邮箱地址</div>
<div>
<input type="text" name="mail" onblur="checkMail(this)"/>
</div>
<div class="errorinfo" id="maildiv">邮箱地址错误,请按要求填写</div>
</td>
</tr>
<tr>
<th>
<input type="submit" value="注 册"/>
</th>
</tr>
</table>
</form>
</body>
</html>