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:

