Jump to content

Recommended Posts

Ok guys, I am definitely not the best at javascript, but I don't think this is a coding problem. My issue is this:

 

I am writing a registration script using jQuery to do immediate validation. It all works just fine, but I cant figure out the password thing.

 

//CHECK PASSWORD 
function password_check(){	
var password = $('#password').val();
var password1 = $('#password1').val();

if(password == "" || password.length < {
$('#password').css('border', '2px red solid');
$('#password_check').html("<img src='img/cross.png' id='cross' /> Password must be 8 characters!");
    } else {
        //Since password is long enough, color it green.
        $('#password').css('border', '2px green solid');
        $('#password_check').html("<img src='img/tick.png' id='tick' />");
        
        //Password is long enough, what about password1? Check em both now.
        if(password1 == "" || password1.length < {
        $('#password1').css('border', '2px red solid');
        $('#password1_check').html("<img src='img/cross.png' id='cross' /> Password must be 8 characters!");
        } else {
        //Passwords are both long enough, do they match?
            if(password != password1){
            $('#password1').css('border', '2px red solid');
            $('#password1_check').html("<img src='img/cross.png' id='cross' /> Passwords do not match!!");        
            } else {    
                $('#password1').css('border', '2px green solid');
                $('#password1_check').html("<img src='img/tick.png' id='tick' />");            
            }
        }
    }
}

 

All the code works, but is there a way for me to make it so that the verify password form does not become RED with an error until the user actually starts to type? With this code, as soon as password reaches 8 characters, it automatically errors the verify field.

Link to comment
https://forums.phpfreaks.com/topic/249928-login-problem/
Share on other sites

for your password input set the max length.

 

<input type="password" id="password" name="password" maxlength="8"/>
<input type="password" id="password1" name="password1" maxlength="8"/>

this is a good precautionary step.. but should not be used as the only safeguard, as it can be tampered with..

OP can you explain a little further as to why this is not working for you.. I looked through your code and it appears like it should be doing what you want it to.. if the password length is greater than 8 characters, it will be bordered red and a message will appear..

Link to comment
https://forums.phpfreaks.com/topic/249928-login-problem/#findComment-1282778
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.