<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<script>
//校验名字
function checkUsername(){
//定义正则字符规则
var usernameReg = /^[a-zA-Z0-9]{5}$/
//获取用户名
var username = document.getElementById("usernameInput").value
//获取提示框元素
var ts = document.getElementById("usernameInputSpan")
if(!usernameReg.test(username)){
ts.innerText = "请输入五位字母数字"
return false
}
ts.innerText = "OK"
return true
}
//校验密码
function checkUserPwd(){
//定义正则字符规则
var userPwdReg = /^[0-9]{6}$/
//获取密码元素
var userPwd = document.getElementById("userPwd").value
//获取提示框元素
var ts = document.getElementById("userPwdSpan")
if(!userPwdReg.test(userPwd)){
ts.innerText = "请输入六位数字"
return false
}
ts.innerText = "OK"
return true
}
//校验密码
function checkUserPwdCon(){
//获取密码元素
var userPwd = document.getElementById("userPwd").value
var userPwdCon = document.getElementById("userPwdCon").value
//获取提示框元素
var ts = document.getElementById("userPwdSpanCon")
if(userPwd!=userPwdCon){
ts.innerText = "密码不一致"
return false
}
ts.innerText = "OK"
return true
}
//表单在提交时,校验用户名和密码格式,格式OK才会提交
function checkForm(){
var result1 = checkUsername()
var result2 = checkUserPwd()
var result3 = checkUserPwdCon()
return result1&&result2&&result3
}
</script>
<style>
.tb{
border: 5px solid rgb(13, 154, 69);
margin: auto;
width: 300px;
border-radius: 3px;/*
border-color: green;
border-width: 3px; */
}
.ipt{
border: 0px ;
}
td{
border-color: rgb(4, 156, 4);
border-width: 1px;
border-style: solid;
}
.btn1{
background-color: antiquewhite;
font-family: 幼圆;
}
.btn2{
background-color: antiquewhite;
color: blue;
font-family: 幼圆;
}
.buttonC{text-align: center;}
#usernameInputSpan, #userPwdSpan, #userPwdSpanCon {
color: rgb(235, 84, 84);
font-size: xx-small;
}
</style>
</head>
<body>
<h2 style="color: #000;text-align: center; font-family: 'Courier New', Courier, monospace;">欢迎注册</h2>
<h3 style="color: #000;text-align: center; font-family: 'Courier New', Courier, monospace;">请注册</h3>
<form method="post" action=" login.html" onsubmit="return checkForm()">
<table class="tb" cellspacing="1px">
<tr class="ltr">
<td >请输入账号</td>
<td >
<input class="ipt" type="text" id="usernameInput" onblur="checkUsername()"/>
<span id="usernameInputSpan"></span>
</td>
</tr>
<tr class="ltr">
<td>请输入密码</td>
<td >
<input class="ipt" type="password" id="userPwd" onblur="checkUserPwd()" />
<span id="userPwdSpan"></span>
</td>
</tr>
<tr class="ltr">
<td>请确认密码</td>
<td >
<input class="ipt" type="password" id="userPwdCon" onblur="checkUserPwdCon()" />
<span id="userPwdSpanCon"></span>
</td>
</tr>
<tr class="ltr" style="margin: auto;">
<td colspan="3" class="buttonC">
<!-- <input class="btn1" type="submit" value="注册 " onclick=""> -->
<input class="btn1" type="reset" value="重置">
<button class="btn2"> <a href="login.html">注册</a></button>
</td>
</tr>
</table>
</form>
</body>
</html>