9 Develop a webpage for validation of form fields using regular expressions. It should also display information about Password Strength is "Weak", "Medium", "Strong"

Program:

<!DOCTYPE html>

<html>

    <head>

        <script type='text/JavaScript'>

            function validate()

            {

                var pass = document.getElementById("pass").value;

                var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})");

                var mediumRegex = new RegExp("^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})");

               

                if(strongRegex.test(pass))

                {

                    document.getElementById("e").innerText =" Strong Password ";

                }

                else if(mediumRegex.test(pass))

                {

                    document.getElementById("e").innerText =" Medium Password ";

                }

                else

                {

                    document.getElementById("e").innerText =" Weak Password ";

                }

            }

        </script>

    </head>

    <body>

        <form>

            Enter Password: <input type="password" id="pass" onkeyup="validate()">

            <p id = "e"> </p>

        </form>



    </body>

</html>


Output:


Previous
Next Post »