Page 1 of 1

Regex javascript IE compatibility issue

Posted: Tue Dec 15, 2009 10:21 am
by syamk
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

Re: Regex javascript IE compatibility issue

Posted: Wed Dec 16, 2009 10:28 am
by ridgerunner
I can confirm the same results on my IE6 test box here (XP Pro SP2). I'm running IE 6.0.2900.2180.xpsp_sp2_rtm.040803-2158.

I can see no logic error in your regex (it should work just fine)

I can also report that Opera 10.10 and Firefox 2.0.0.20 both handle the regex correctly.

Looks like another IE6 bug.

Re: Regex javascript IE compatibility issue

Posted: Thu Dec 17, 2009 7:49 am
by syamk

You might be right. It should be a bug coming from the VBScript/JScript engine which used by IE6. See details below. But i hear that for some weird reason, IE8 with the same VBScript/JScript engine versions is not smitten.

This is what i found with some sifting.
1. While finding the lower count for occurrences, counting starts from the end of the first lookahead match. Albeit this, final matches will be made only from the start of the string.
2. For upper count, behavior is as expected.

More here: http://regexadvice.com/blogs/mash/archi ... d-bug.aspx

The solution which i'm adopting is : (?=^[\w%&?#=-]{8,12}$)(?=.+\d)(?=.+[a-zA-Z]).+