This is about a strange behavior IE shows for a regex matching Im trying to do.
Here is a password matching expression Im trying to use for matching the below conditions.
- Must contain minimum 8 to 20 characters, mandatorily including one letter and number
- May include only one of the following special characters: %,&, _, ?, #, =, -
- Cannot have any spaces
^(?=.{0,11}\d)(?=.{0,11}[a-zA-Z])[\w%&?#=-]{8,12}$
and the javascript to do the match is
function fnIsPassword(strInput){
alert("strInput : " + strInput);
var regExp =/^(?=.{0,11}\d)(?=.{0,11}[a-zA-Z])[\w%&?#=-]{8,12}$/;
if(strInput.length > 0){
return (regExp.test(strInput));
}
return false;
}
alert(fnIsPassword(“1231231”)); //false
alert(fnIsPassword(“sdfa4gggggg”)); //FF: true, false in IE
alert(fnIsPassword(“goog1234#”)); //FF: true , false in IE
The problem as stated above is that IE gives me false for the last 2 matches.
My IE version is 6.0.2900.5512.xpsp_sp3_gdr.090804-1435 on win XP ; ScriptEngineMajorVersion() = 5 ScriptEngineMinorVersion() = 7.
I got it reproduced on a colleague’s machine with the same configuration.
Somehow IE does the {8,12} count constraints after the first digit is matches.
Thus i see that abc45678901 is matched and abc4567890 is not matched ( notice that the counting starts from he first digit match)
Anyone can reproduce this issue ? Any workarounds ? .
Thanks in advance,
mays