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> |
chevron_right
filter_none
Output:


Recommended Posts:
- How to validate URL using regular expression in JavaScript?
- How to validate an input is alphanumeric or not using JavaScript ?
- How to validate email address using RegExp in JavaScript ?
- Password Matching using JavaScript
- Show and hide password using JavaScript
- JavaScript | Program to generate one-time password (OTP)
- HTML | DOM Anchor password Property
- HTML | DOM Area password Property
- HTML | <input type="password">
- HTML | DOM Input Password Object
- HTML | DOM Input Password name Property
- HTML | DOM Input Password value Property
- HTML | DOM Input Password type Property
- HTML | DOM Input Password placeholder Property
- HTML | DOM Input Password select() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



