我創建了一個註冊頁面,用戶可以註冊,我試着做一個檢查:電子郵件有效,電子郵件匹配,密碼符合長度要求和密碼匹配。但它不能正常工作。 HTML代碼是相同的形式Javascript電子郵件和密碼驗證
電子郵件錶行:
<tr>
<td></br>Email Address:</td>
</tr>
<tr>
<td><input id="em100" type="email" name="email1" required>
</td>
</tr>
<tr>
<td></br>Confirm Email Address:</td>
</tr>
<tr>
<td><input id="em101" type="email" name="email2" required></td>
</tr>
密碼錶行:
<tr>
<td></br>Password:</td>
</tr>
<tr>
<td><input id="pw100" type="password" name="pass1" required></td>
</tr>
<tr>
<td></br>Confirm Password:</td>
</tr>
<tr>
<td><input id="pw101" type="password" name="pass2" required></td>
</tr>
提交錶行:
<tr>
<td style="padding-top: 10px;"></br><input type="submit" value="Register" onclick="regValidation();"></td>
</tr>
的JavaScript代碼:
function regValidation()
{
document.getElementById('td100').innerHTML = "";
event.preventDefault ? event.preventDefault() : event.returnValue = false;
var email1 = document.getElementById('em100').value;
var email2 = document.getElementById('em101').value;
var pass1 = document.getElementById('pw100').value;
var pass2 = document.getElementById('pw101').value;
if (document.getElementById('em100').checkValidity()) {
if (email1 = email2) {
if (pass1 = pass2) {
if (pass1.length >= @minPass || pass1.length <= @maxPass) {
return true && regSuccess();
} else {
document.getElementById('td100').innerHTML += "</br>Password must be @minPass - @maxPass characters.";
}
} else {
document.getElementById('td100').innerHTML += "</br>Passwords do not match.";
}
} else {
document.getElementById('td100').innerHTML += "</br>Emails do not match.";
}
} else {
document.getElementById('td100').innerHTML += "</br>Emails are not valid.";
}
}
function regSuccess()
{
alert("Thank you for signing up!");
document.getElementById('fm101').submit();
return;
}
什麼是不工作?你有什麼錯誤嗎? – user1777136
如果你使用的是asp.net,那麼你可以利用asp.net內置的驗證器 – RohitS
也如上面提到的答案,你不等於你分配的值=你需要==來等價值 – RohitS