Categories
Development Java Javascript

How to to check if confirmed password is same as the first password in javascript?

I’m having trouble validating if the entered password is same as confirmed password. It doesnt show the text message if it isnt the same or if it is same. It only shows the notice that the password field is empty?

HTML

<div>
  <label>Geslo:</label>
  <input type="password" id="myInput2" oninput="myFunction2()" name="password" id="koda"><br />
  <p id="demo2"></p>

</div>
<div>
  <label>Ponovi geslo:</label>
  <input type="password" name="repassword" oninput="myFunction3()" id="myInput3"><br />
  <p id="demo3"></p>
</div>

JS

function myFunction2() {
  var mediumRegex = new RegExp("^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})");
  if (m.value === "") {
    document.getElementById("demo2").innerHTML = "Prosim vnesite vaš geslo!";
    return false;

  } else if (mediumRegex.test(m.value) == false) {
    document.getElementById("demo2").innerHTML = "Geslo mora vsebovati vsaj eno veliko začetnico in številko!(Min.6 znakov)";
    return false;

  } else if (mediumRegex.test(m.value) === true) {
    document.getElementById("demo2").innerHTML = "";
    return true;

  }
}

function myFunction3() {
  if (n.value === "" || n.value == NULL) {
    document.getElementById("demo3").innerHTML = "Prosim ponovno vnesite vaše geslo!";
  } else if (n.test(m.value) === false) {
    document.getElementById("demo3").innerHTML = "Vaše geslo se ne ujema!";

  } else if (n.test(m.value) === true) {
    document.getElementById("demo3").innerHTML = "Vaše geslo se  ujema!";

  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *