1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Validate password field HELP

Discussion in 'JavaScript' started by Elbrain, Feb 7, 2023.

  1. #1
    Please i need to validate the password field this way, must contain atleast one uppercase letter, lowercase, number.
    please i need this to be in someway this format not in jquery cause i have other if statement for other fields.
    Not a JS Expert tho.
    Thanks
    if(!/^[a-zA-Z]*$/g.test(document.regForm.password.value)) {
    alert("Password must contain an Alphabet(Upper ), Number,");
    document.regForm.lastname.focus();
    return false;
    }
     
    Elbrain, Feb 7, 2023 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #2
    qwikad.com, Feb 8, 2023 IP
  3. Elbrain

    Elbrain Active Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    66
    #3
    if(!firstpassword.match((/^(?=.\d)(?=.[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/))) {
    alert("Password must be Alphanumeric");
    return false;
    }

    Above is the code i want.

    But It print "Password must be alphanumeric" even if it has combination of both
     
    Elbrain, Feb 8, 2023 IP
  4. Elbrain

    Elbrain Active Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    66
    #4
    ^(?=.\d)(?=.[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$
    How can I limit the above expression to just aphanumeric and regardless of case?
     
    Elbrain, Feb 8, 2023 IP
  5. Elbrain

    Elbrain Active Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    66
    #5
    if(firstpassword.match(/[^a-z0-9]+/i)) {
    ("password must be alphanumeric");
    }

    Please and also the above code does not work
     
    Elbrain, Feb 8, 2023 IP
  6. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #6
    Shouldn't be like this?

    if(/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).*$/.test(document.regForm.password.value)) {
    alert("Password must contain an Alphabet(Upper ), Number,");
    document.regForm.lastname.focus();
    return false;
    }
     
    qwikad.com, Feb 8, 2023 IP
  7. Elbrain

    Elbrain Active Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    66
    #7
    It dosen't work
    Here is the whole code
    -must have atleast one number
    <html>
    <script>
    // PASSWORD
    // PASSWORD
    function validateForm() {
    var firstpassword = document.regForm.password.value;
    firstpassword = firstpassword.trim();
    var secondpassword = document.regForm.password2.value;
    secondpassword = secondpassword.trim();

    if(firstpassword==null || firstpassword==""){
    alert("Please enter Password");
    return false;
    }
    if(/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).*$/.test(document.regForm.password.value)) {
    alert("Password must contain an Alphabet");
    document.regForm.password.focus();
    return false;
    }
    //minimum password length validation
    if(firstpassword.length < 8){
    alert("**Password length must be atleast 8 characters");
    return false;
    }
    //maximum length of password validation
    if(firstpassword.length > 15) {
    alert("**Password length must not exceed 15 characters");
    return false;
    }
    /*
    if(secondpassword==null || secondpassword==""){
    alert("Please retype password");
    return false;
    }*/
    }
    </script>
    <form action="/SMT.php" name="regForm" onsubmit="returnvalidateForm()" enctype="multipart/form-data" method="POST">
    <p> Password </p>
    <input type='password' class='input' name='password'>
    <p> Re-type Password </p>
    <input type='password' class='input' name='password2'>
    <input type='submit' value='SUBMIT' class='input' name='Submit' style='text-align:center;'>
    </form>
    </html>
     
    Elbrain, Feb 8, 2023 IP