admin管理员组文章数量:1318156
^(?=[\w\-%&?#=]+\d)(?=[\w\-%&?#=]+[a-zA-Z])[\w\-%&?#=]{8,12}$
Was meant to match the below conditions in a JavaScript based new-password check,
- 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
With above regex, goog123#
was matched in FF3.5. However this fails in IE6. Anyone knows what went wrong here? Is this a patibility issue?
JavaScript used to test the matching
function fnIsPassword(strInput)
{
alert("strInput : " + strInput);
var regExp =/^(?=.{0,19}\d)(?=.{0,19}[a-zA-Z])[\w%&?#=-]{8,20}$/;
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
^(?=[\w\-%&?#=]+\d)(?=[\w\-%&?#=]+[a-zA-Z])[\w\-%&?#=]{8,12}$
Was meant to match the below conditions in a JavaScript based new-password check,
- 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
With above regex, goog123#
was matched in FF3.5. However this fails in IE6. Anyone knows what went wrong here? Is this a patibility issue?
JavaScript used to test the matching
function fnIsPassword(strInput)
{
alert("strInput : " + strInput);
var regExp =/^(?=.{0,19}\d)(?=.{0,19}[a-zA-Z])[\w%&?#=-]{8,20}$/;
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
Share
Improve this question
edited Jun 13, 2011 at 4:36
Yi Jiang
50.2k16 gold badges138 silver badges136 bronze badges
asked Dec 14, 2009 at 14:02
maysmays
3971 gold badge3 silver badges11 bronze badges
2
- 13 If something fails on IE6, there's nothing wrong. – Rubens Farias Commented Dec 14, 2009 at 14:05
- 1 @Rubens Quite possibly the most funny and accurate statement I have heard in a long while – Chris Commented Apr 12, 2011 at 13:28
2 Answers
Reset to default 4The regex has a number of issues. Try this one instead:
^(?=.{,19}\d)(?=.{,19}[a-zA-Z])[\w%&?#=-]{8,20}$
which is:
^ # start-of-string (?=.{,19}\d) # look-ahead: a digit within 20 chars (?=.{,19}[a-zA-Z]) # look-ahead: a letter within 20 chars [\w%&?#=-]{8,20} # 8 to 20 chars of your allowed range $ # end-of-string
This is what i found with some sifting.
- 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.
- For upper count, behavior is as expected.
The final regex for this issue is
/(?=^[\w%&?#=-]{8,12}$)(?=.+\d)(?=.+[a-zA-Z]).+/
本文标签: regexJavaScriptRegExp compatibility in IE Stack Overflow
版权声明:本文标题:regex - JavaScriptRegExp compatibility in IE- Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742040150a2417514.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论