我的简单密码验证有问题。
这些是验证所做的事情
- 检查密码是否少于 8 个字符
- 检查是否超过 15 个字符
- 检查新密码和重新输入的密码是否不匹配
当两个密码匹配时提交表单,即使小于或大于验证
请看我的代码:
function on_submit(dest) {
var objForm = document.LogonForm;
var strMissingInfo = "";
if (dest == 'logon') {
if (objForm.current.value != "") {
if (objForm.new1.value.length < 8 || objForm.new1.value.length > 15) {
strMissingInfo += "\n Password must be 8 to 15 characters long";
} else if (objForm.retype.value != objForm.new1.value) {
strMissingInfo += "\n Password mismatch!";
}
if (strMissingInfo != "") {
alert(strMissingInfo);
} else {
alert(strMissingInfo);
objForm.action.value = dest;
objForm.submit();
}
}
}
}
--- HTML部分
<input type="password" id="current" name="current"
onKeyPress="return isNumberKey(event)" style="width: 180px"
tabindex="1" required/>
<input type="password" id="new1" name="new1"
onKeyPress="return isNumberKey(event)" style="width: 180px"
tabindex="2" required />
<input type="password" id="retype" name="retype"
onKeyPress="return isNumberKey(event)" style="width: 180px"
tabindex="3" required />
<a href="javascript:;">
<input id="logonButton" class="submit"
type="submit" name="Submit" value="Confirm" tabindex="4"
onclick="on_submit('logon')" />
</a>