imperialized Posted October 27, 2011 Share Posted October 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/249928-login-problem/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 27, 2011 Share Posted October 27, 2011 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"/> Quote Link to comment https://forums.phpfreaks.com/topic/249928-login-problem/#findComment-1282768 Share on other sites More sharing options...
AyKay47 Posted October 27, 2011 Share Posted October 27, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/249928-login-problem/#findComment-1282778 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 27, 2011 Share Posted October 27, 2011 You should use lesser than nine cause lesser than eight does not include eight. Edit: this is because you want the max length to be 8 and not7 Quote Link to comment https://forums.phpfreaks.com/topic/249928-login-problem/#findComment-1282796 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.