复制代码 代码如下:
<!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=gb2312">
<meta content="刘江波">
<script type="text/javascript">
function login(){
var userName=document.getElementById("userName").value;
var pwd=document.getElementById("pwd").value;
var repwd=document.getElementById("repwd").value;
var address=document.getElementById("address").value;
var matchResult=true;
if(userName==""||pwd==""||repwd==""||address==""){
alert("请确认是否有空缺项!");
matchResult=false;
}else if(userName.length<6||userName.length>20){
alert("用户名长度应在6到20个字符之间!");
matchResult=false;
}else if(userName==pwd||userName==repwd){
alert("密码或重复密码不能和用户名相同!");
matchResult=false;
}else if(pwd.length<6||pwd.length>20||repwd.length<6||repwd.length>20){
alert("密码或重复密码长度应在6到20个字符之间!");
matchResult=false;
}else if(pwd!=repwd){
alert("密码和重复密码不同,请重新输入!");
matchResult=false;
}else if(userName.length<6||userName.length>20){
alert("用户名长度应在6到20个字符之间!");
matchResult=false;
}
if(matchResult==true){
var mailreg = /^\w+@\w+(\.\w+)+$/;
if(!address.match(mailreg)){
alert("邮箱格式不正确");
matchResult=false;
}
}
if(matchResult==true){
if(userName.charAt(0)>=0&&userName.charAt(0)<=9){
alert("用户名不能以数字字符开始!");
matchResult=false;
}
}
return matchResult;
}
</script>
<title>用户注册及验证</title>
</head>
<body>
<center>
<form action="http://www.ytu.edu.cn" onsubmit="return login()" method="post">
<table bgcolor="#6666FF" cellspacing="0" cellpadding="0" valign="top">
<tr>
<td colspan="2" bgcolor="#3366FF">用户注册</td>
</tr>
<tr>
<td>登录用户名</td>
<td><input type="text"></td>
</tr>
<tr>
<td>登录密码</td>
<td><input type="password"></td>
</tr>
<tr>
<td>重复输入密码</td>
<td><input type="password"></td>
</tr>
<tr>
<td>有效邮箱地址</td>
<td><input type="text"></td>
</tr>
<tr>
<!--<td></td>-->
<td colspan="2">
<input type="submit" value="登录">
<input type="button" value="取消"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
效果实现:
您可能感兴趣的文章: