Log in

View Full Version : Javascript language for counting characters


boobiesonthetree
Feb 11, 2008, 12:32 PM
I wonder if anyone can help me please,

I am trying to write code into my program
The code needs to be for counting characters in a password
The user enters a password which must be between 7-15 characters long
If the user enters outsuide this rule then an error message must come up stating exactly how many characters the user did enter and telling them it must be between 7-15 characters.
I have managed to do the error message for the wrong amount of characters but I can't get my head around displaying the amount of characters the user entered
If anybody can help pleaseeeee do thank you

Emma

manchester thani
Mar 31, 2008, 08:39 AM
Try using indexAt and charAt methods buddy... but I am not sure..

jstrike
Apr 9, 2008, 01:40 PM
function checkPassLength(password);
var passLen = password.length;
if(passLen<7) {
alert("You entered " + passLen + " characters, your password is too short.");
return false;
}

if(passLen>15) {
alert("You entered " + passLen + " characters, your password is too long.");
return false;
}

return true;
}