Validate a password using HTML and JavaScript

The task is to validate the password using HTML and JavaScript.
A password is correct if it contains:
- At least 1 uppercase character.
- At least 1 lowercase character.
- At least 1 digit.
- At least 1 special character.
- Minimum 8 characters.
Example:
<!DOCTYPE html> <html> <head> <title>validate password</title> <script type="text/javascript"> function test_str() { var res; var str = document.getElementById("t1").value; if (str.match(/[a-z]/g) && str.match( /[A-Z]/g) && str.match( /[0-9]/g) && str.match( /[^a-zA-Z\d]/g) && str.length >= 8) res = "TRUE"; else res = "FALSE"; document.getElementById("t2").value = res; } </script> </head> <body> <p> String: <input type="text" placeholder="abc" id="t1" /> <br/> <br/> <input type="button" value="Check" onclick="test_str()" /> <br/> <br/> Output: <input type="text" id="t2" readonly/> </p> </body> </html> |
Output:
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!




