Tuesday 15 June 2010

javascript - test() regex function not working in IE? -



javascript - test() regex function not working in IE? -

i'm having problem figuring out why function works in chrome, 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!" homecoming 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!"; homecoming obj; } homecoming obj; }

the user enters password in input box , when click out of box string validated function. in chrome works fine, in ie appears test() behaving strangely.

i added debug messages , found when come in number in input box (and click out of it) ie displays "lower" debug message chrome displays "number" debug message expected. what's wrong code?

edit: after guys pointed out stupidity of how string beingness evaluated (i think grabbed script supposed record every type of character) i'm doing this:

if(auppercase.test(p)) { numupper++; }; if(alowercase.test(p)) { numlower++; }; if(anumber.test(p)) { numnums++; }; if(aspecial.test(p)) { numspecials++; };

javascript google-chrome internet-explorer

No comments:

Post a Comment