我的密码验证无法正常执行

时间:2019-06-05 09:14:32

标签: html asp.net

因此,我尝试使用JS进行密码验证,它可以正常工作(当密码不相同(OnKeyUp)时,将文本框显示为红色),但不会使按钮阻止实际的注册。 如果您能看一下我的代码,我将非常感谢。

function auth() {

  var password = document.getElementById("password");
  var password2 = document.getElementById("Repassword")
  var PassDont = document.getElementById("passDont")
  if (password.value != password2.value()) {
    PassDont.innerHTML = "<h3> Passwords Don't match </h3>";
    password2.style.backgroundColor = "#ff3232";
    return false;
  } else {
    password2.style.backgroundColor = "#8fff89";
    PassDont.innerHTML = " "
  }

}
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">

  <div id="container">

    <h1 class="RegHead">Registeration</h1>

    <label class="input-label" for="username">username</label>
    <input class="user-input" type="text" id="username" name="user_name" pattern="[A-Za-z0-9]+" maxlength="12" title="Username should be in English and numbers, 12 letters max" required autocomplete="off" />

    <br />

    <label class="input-label" for="password">Password:</label>
    <input class="user-input" type="password" id="password" name="password" pattern=".{6,12}" required title="Password have to contain between 6 to 12 letters" required autocomplete="off" />

    <br />

    <label class="input-label" for="Re-password">Re-enter Password:</label>
    <input class="user-input" type="password" id="Repassword" name="repassword" onkeyup="return auth();" autocomplete="off" />

    <br />

    <asp:Button runat="server" Text="Register" OnClick="OnSubmitClick" OnClientClick="return auth();" />

    <span id="passDont"></span>
  </div>


</asp:Content>

1 个答案:

答案 0 :(得分:-1)

if (password.value != password2.value())

if (password != password2)