I’m very stumped here. I’m trying to take some server-side PHP and introduce some JavaScript that does the same thing – giving hints to the user as they type. I have the following, which is attempting to find all lowercase letters, uppercase letters, and numbers 0 or more times; it then deletes those characters, leaving behind a string containing everything else. I then take the length of this and compare it to a variable maxSymbols, which is 5.
I cannot get this to evaluate properly… what am I missing here?
else if(passwordValue.replace(/([a-zA-Z0-9])*/, '').length > maxSymbols){
// Check the maximum number of symbols in the password.
document.getElementById("passwordHint").innerHTML = "You've used too many symbols, " + maxSymbols + " is the maximum.";
document.getElementById("passwordHint").style.color = "red";
}
You are missing the
gmodifier for your regular expression. Without theg, you are only replacing the first match.Try
if(passwordValue.replace(/([a-zA-Z0-9])*/g, '').length > maxSymbols).Hope this helps,
Pete