js两次输入密码验证,可以参考如下代码:
<FORM METHOD=POST ACTION=""><input type="password" id="input1">
<input type="password" id="input2">
<input type="button" value="test" onclick="check()">
</FORM>
<script>
function check()
{
with(document.all){
if(input1.value!=input2.value)
{
alert("false")
input1.value = ""
input2.value = ""
}
}
}
</script>
JavaScript验证两次输入密码是否相同,通过去判断两次输入的密码是否相同来实现,
下面是html代码<FORM METHOD=POST ACTION="">
<input type="password" id="input1">
<input type="password" id="input2">
<input type="button" value="test"
onclick="check()">
</FORM>下面是javascript的代码<script>
function check()
{
with(document.all){
if(input1.value!=input2.value)
{
alert("false")
input1.value = ""
input2.value = ""
}
else document.forms[0].submit()
}
不是不能判断,而是你的属性名写错了,那个classes=document.form1........是定义为classes ,而下面又定义一个info 说if(info.lenght>40){}...............当然会出错<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javaScript">
function check()
{
var username = document.form1.userName.value
var name = document.form1.name.value
var room = document.form1.room.value
var info = document.form1.classes.value
var phone = document.form1.phone.value
var password = document.form1.passWord.value
var password2 = document.form1.passWord2.value
if (username==""|| password==""||room==""||info==""||phone==""||name==""||password2=="")
{
alert("任意信息不能为空,请重新填写!")
return false
}
else if(username.length>20){
alert("用户名不能超过20个字符,请重新输入!")
return false
}
else if(password.length<6){
alert("密码不能小于6个字符,请重新输入!")
return false
}
else if(phone.length >20)
{
alert("联系方式长度不能超过20字符!")
return false
}
else if (isNaN(phone))
{
alert("联系方式必须是数字")
return false
}
else if (info.length >40)
{
alert("学院班级信息长度不能超过40字符!")
return false
}
else if (password!=password2)
{
alert("2次密码输入不一致!")
return false
}
else{
return true
}
}
</script>
<body>
<div align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td background="head.jpg" width="600" height="142"></td>
</tr>
</table>
<p></p>
<form id=form1 name="form1" method = "post" action = "addUser.do" onsubmit="return check()">
<table>
<tr><td>用户注册</td></tr></table>
<table>
<tr><td>用户名:</td><td><input type="text" name="userName" ></td></tr>
<tr><td>真实姓名:</td><td><input type="text" name="name"></td></tr>
<tr><td>寝室信息:</td><td><input type="text" name="room" ></td></tr>
<tr><td>联系电话:</td><td><input type="text" name="phone" ></td></tr>
<tr><td>学院班级:</td><td><input type="text" name="classes" ></td></tr>
<tr><td>密码:</td><td><input type="password" name="passWord"></td></tr>
<tr><td>再次输入密码:</td><td><input type="password" name="passWord2"></td></tr>
<tr><td><label><div align="center"><input type="submit" value="确定" ></div></label></td>
<td><div align="center"><input type="reset" value="重置" ></td>
<td><div align="center"><a href="/WaterFront/userLogin.jsp">返回登录</td>
</tr>
</table>
</form>
</body>
</html>
</BODY>
</HTML>