I'm having trouble figuring out why this function works in chrome, but not IE:
function isOkPass(p){
var categories = 0;
var anUpperCase = /[A-Z]/;
var aLowerCase = /[a-z]/;
var aNumber = /[0-9]/;
var aSpecial = /[!|@|#|$|%|^|&|*|(|)|-|_]/;
var obj = {};
obj.result = true;
if(p.length < 8){
obj.result=false;
obj.error="Password not long enough!"
return obj;
}
var numUpper = 0;
var numLower = 0;
var numNums = 0;
var numSpecials = 0;
for(var i=0; i<p.length; i++){
if(anUpperCase.test(p[i])) {
numUpper++;
console.dir('UPPPER');
} else if(aLowerCase.test(p[i])) {
numLower++;
console.dir('LOWEERR');
} else if(aNumber.test(p[i])) {
numNums++;
console.dir('NUMBER');
} else if(aSpecial.test(p[i])) {
numSpecials++;
console.dir('special');
}
}
if(numUpper >= 1){
categories += 1;
}
if(numLower >= 1){
categories += 1;
}
if(numNums >= 1){
categories += 1;
}
if(numSpecials >= 1){
categories += 1;
}
if(categories < 3){
obj.categories= categories;
obj.result= false;
obj.error= "Password not complex enough!";
return obj;
}
return obj;
}
The user enters a password in an input box and when they click out of the box the string is validated with this function. In chrome it works fine, but in IE it appears test()
is behaving strangely.
I added some debug messages and found that when I enter a number in the input box (and click out of it) IE displays the "LOWER"
debug message where as chrome displays the "NUMBER"
debug message as expected. What's wrong with my code?
Edit: after you guys pointed out the stupidity of how the string was being evaluated (I think I grabbed a script that was originally supposed to record every type of character) I'm now just doing this:
if(aUpperCase.test(p)) {
numUpper++;
};
if(aLowerCase.test(p)) {
numLower++;
};
if(aNumber.test(p)) {
numNums++;
};
if(aSpecial.test(p)) {
numSpecials++;
};