对密码进行正则的验证。。如果两个密码正确,就会跳到另一个页面,不然则会显示一个对话框,同时会有红色警告字。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>password_.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function mima(){
var reg =/^[a-zA-Z0-9]\w{5,17}$/;
var username = document.getElementById("p1").value;
var flag = reg.test(username);
alert(flag);
if (!flag) {
alert("密码输入有误!,请重输");
return false;
}else{
return check();
}
}
function check(){
if(document.getElementById("p1").value!=document.getElementById("p2").value){
alert("密码与验证密码不一致!");
document.getElementById("p1").value="";
document.getElementById("p2").value="";
document.getElementById("sid").innerHTML = "出错信息:两个密码不相同。。";
return false;
}else{
return true;
}
}
</script>
</head>
<body>
<form action="/Homework/servlet/TestServlet">
密码:
<input type="password" / id="p1">
<br />
验证密码:
<input type="password" id="p2" />
<font color="red"><span id="sid"></span>
</font>
<br />
<p>
<input type="submit" mima()" value="提交" />
<input type="reset" value="重置" />
</p>
</form>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>password_.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function mima(){
var reg =/^[a-zA-Z0-9]\w{5,17}$/;
var username = document.getElementById("p1").value;
var flag = reg.test(username);
alert(flag);
if (!flag) {
alert("密码输入有误!,请重输");
return false;
}else{
return check();
}
}
function check(){
if(document.getElementById("p1").value!=document.getElementById("p2").value){
alert("密码与验证密码不一致!");
document.getElementById("p1").value="";
document.getElementById("p2").value="";
document.getElementById("sid").innerHTML = "出错信息:两个密码不相同。。";
return false;
}else{
return true;
}
}
</script>
</head>
<body>
<form action="/Homework/servlet/TestServlet">
密码:
<input type="password" / id="p1">
<br />
验证密码:
<input type="password" id="p2" />
<font color="red"><span id="sid"></span>
</font>
<br />
<p>
<input type="submit" mima()" value="提交" />
<input type="reset" value="重置" />
</p>
</form>
</body>
</html>
转载于:https://blog.51cto.com/myxiaoyi/209819