Regex javascript IE compatibility issue

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
syamk
Forum Newbie
Posts: 2
Joined: Tue Dec 15, 2009 10:20 am

Regex javascript IE compatibility issue

Post 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
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: Regex javascript IE compatibility issue

Post 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.
syamk
Forum Newbie
Posts: 2
Joined: Tue Dec 15, 2009 10:20 am

Re: Regex javascript IE compatibility issue

Post 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]).+
Post Reply