<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改密码的验证</title>
</head>
<h1>修改密码</h1>
<b id="passModifyMess" style="color: red;"></b>
<form action="modifyPassword.html" method="post">
<table border="1" cellpadding="0" width="20%">
<tr>
<td>旧密码:</td>
<td><input type="password" id="oldpass" /></td>
</tr>
<tr>
<td>新密码:</td>
<td><input type="password" id="newpass" /></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type="password" id="confirmpass" /></td>
</tr>
<tr>
<td>验证码:</td>
<td><input type="text" id="code" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" id="submit" value="提交" />
<input type="reset" id="reset" value="重置" />
</td>
</tr>
</table>
</form>
<body>
<script>
window.onload = function() {
var reset = document.getElementById(‘reset‘);
var fm = document.getElementsByTagName(‘form‘)[0];
var passModifyMess = document.getElementById(‘passModifyMess‘);
reset.onclick = function() {
oldpass.value = ‘‘;
newpass.value = ‘‘;
confirmpass.value = ‘‘;
code.value = ‘‘;
oldpass.focus();
};
fm.onsubmit = function() {
if(!/^\w{6,20}$/.test(oldpass.value)) {
passModifyMess.innerHTML = "* 旧密码错误!";
oldpass.value = "";
oldpass.focus();
return false;
}
if(!/^\w{6,20}$/.test(newpass.value)) {
passModifyMess.innerHTML = "* 新密码不合法!";
newpass.value = ‘‘;
newpass.focus();
return false;
}
if(newpass.value != confirmpass.value) {
passModifyMess.innerHTML = "* 两次输入的新密码不一致,请重新输入!";
newpass.value = ‘‘;
confirmpass.value = ‘‘;
newpass.focus();
return false;
}
if(!/^\d{4}$/.test(code.value)) {
passModifyMess.innerHTML = "* 验证码错误!";
code.value = ‘‘;
code.focus();
return false;
}
return true;
};
};
</script>
</body>
</html>