loader image

JavaScript program for password validation

Write a JavaScript program for Password validation based on the following conditions

  • Password and confirm password must be same
  • Length of password must be greater than 8 characters
<html>

<body>
    <h1>Password Validation</h1>
    Password: <input type="text" id="pass"><br />
    Confirm Password: <input type="password" id="confirm"><br />
    <input type="submit" onClick="verify()">
    <p id="txt"></p>
    <script>
        function verify() {
            document.getElementById("txt").innerHTML = "";
            if (document.getElementById("pass").value != document.getElementById("confirm").value) {
                document.getElementById("txt").innerHTML += "Password and confirm password must be same.";
            }
            if (document.getElementById("pass").value.length < 8) {
                document.getElementById("txt").innerHTML += "<br/>Password must be greater than 8 characters.";
            }
        }
    </script>

</body>

</html>
Output
password js
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments