我有以下代碼來驗證電子郵件和密碼重復,并且即使我在表單提交時輸入相同的密碼,也會不斷收到“密碼確實匹配”的錯誤。我有以下代碼。請幫助解決,因為我是新手和學習者。簡單的步驟將有所幫助。提前致謝。
----html----
<head>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<form
id="userForm"
action="signup_otp.html"
method="POST"
name="userForm"
onsubmit="return(validate());"
>
</body>
----script.js---------
//Validation of email and password
function validate() {
document.getElementById("emailAlert").innerHTML="";
var emailVal = /^([A-Za-z0-9_\-\.]) \@([A-Za-z0-9_\-\.]) \.([A-Za-z]{2,4})$/;
if(!document.userForm.email_id.value.match(emailVal)) {
document.getElementById("emailAlert").innerHTML="Enter a valid email format";
//document.getElementById("email_id").focus();
document.userForm.email_id.focus();
//alert(emailAlert);
return false;
}
alert("check passwd")
document.getElementById("passAlert").innerHTML="";
var pw1 = document.getElementById("psw");
var pw2 = document.getElementById("psw_repeat");
console.log(pw1); // console shows null value
console.log(pw2);
if(pw1 != pw2)
{
//alert("Passwords did not match");
document.getElementById("passAlert").innerHTML="Password did not match";
document.userForm.psw.focus();
return false;
} else {
alert("Password created successfully");
return false;
}
return true;
}
uj5u.com熱心網友回復:
------script.js
function validate() {
document.getElementById("emailAlert").innerHTML="";
var emailVal = /^([A-Za-z0-9_\-\.]) \@([A-Za-z0-9_\-\.]) \.([A-Za-z]{2,4})$/;
if(!document.userForm.email_id.value.match(emailVal)) {
document.getElementById("emailAlert").innerHTML="Enter a valid email format";
//document.getElementById("email_id").focus();
document.userForm.email_id.focus();
//alert(emailAlert);
return false;
}
//alert("check passwd");
document.getElementById("passAlert").innerHTML="";
var pw1 = document.getElementById("psw").value;
var pw2 = document.getElementById("psw_repeat").value;
console.log(pw1);
console.log(pw2);
if(pw1 != pw2)
{
//alert("Passwords did not match");
document.getElementById("passAlert").innerHTML="Password did not match";
document.userForm.psw.focus();
return false;
} //else {
//alert("Password created successfully");
//return false;
//}
return true;
}
uj5u.com熱心網友回復:
var pw1 = document.getElementById('psw').value
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422554.html
標籤:
上一篇:CSV檔案的URL鏈接檢查器
