Skip to content
Related Articles
Open in App
Not now

Related Articles

Validate a password using HTML and JavaScript

Improve Article
Save Article
Like Article
  • Last Updated : 16 Apr, 2019
Improve Article
Save Article
Like Article

The task is to validate the password using HTML and JavaScript.

A password is correct if it contains:

  1. At least 1 uppercase character.
  2. At least 1 lowercase character.
  3. At least 1 digit.
  4. At least 1 special character.
  5. Minimum 8 characters.


<!DOCTYPE html>
    <title>validate password</title>
    <script type="text/javascript">
        function test_str() {
            var res;
            var str =
            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";
                res = "FALSE";
            document.getElementById("t2").value = res;
        <input type="text" 
               id="t1" />
        <input type="button"
               onclick="test_str()" />
        <br/> Output:
        <input type="text" 


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!