开发者

Javascript Regex Browser Inconsistancy?

I have a regex开发者_StackOverflow that I am using in an asp.net RegularExpressionValidator to check a TextField.

^(?=.*[a-z])(?=.*\d)(?=.*[A-Z]).{8,}$

The example string I have stumbled on is 'RedCoal1'

Firefox = Matched

IE8 = Matched

Chrome = Matched

IE7 = DOES NOT MATCH

WHY!!!!


The implementation of lookahead in WSH's RegExp as used by IE is just broken. The bug usually pops up in exactly this case, trying to use one regex to verify several things at once.

Plus some older browsers don't support lookahead at all (it wasn't in the original JavaScript spec, though it is now in ECMA-262-3). So all in all it's best to avoid lookahead in browser RegExp.

It would be best to separate out each check (each character class, and length) into manual validation steps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜