如何实现表单提交时,验证两次密码是否一致

来源:互联网 发布:人工智能大立科技 编辑:程序博客网 时间:2024/05/16 14:39
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
<form name="form2" action="sign_in_save.jsp" method="post">
<table width="410" align="center" bgcolor="#9AD3A4">
<tr>
<td width="90" align="center">用&nbsp户&nbsp名&nbsp:</td>
<td><input type="text" name="username" ></td>
</tr>
<tr>
<td width="90" align="center">密&nbsp&nbsp&nbsp&nbsp&nbsp码&nbsp&nbsp:</td>
<td><input type="password" name="password" id="p1"></td>
</tr>
<tr>
<td width="90" align="center">确认密码:</td>
<td><input type="password" name="password1" id="p2"></td>
</tr>
<tr>
<td><input onclick="return check1()" type="submit" name="submit" value="提交" ></td>
<td><input type="reset" name="reste" value="重置"></td>
</tr>

</table>
</form>
</body>
</html>
<script language="JavaScript">
<!-- 
function check1() 
{

if (document.form2.username.value.length == 0) 
{
alert("请输入用户名!");
return false;
}
if (document.form2.password.value.length == 0) 
{
alert("请输入密码!");
return false;
}
String pd1=document.getElementById("p1").value;
String pd2=document.getElementById("p2").value;
if (pd1!=pd2) 
{
alert("两次密码不一致!");
return false;
}
return true;
}
//-->
</script> 
0 0