阅读:3251回复:1
Javascipt 正则表达式问题function test(){ var s = '2008-12-14'; if (!/^\d{4}-\d{1,2}-\d{1,2}$/g.test(s)) alert(s); } ... <input type="button" value='test' onclick="test()" /> 按理来说点button不会有提示,但是现在是点第一下没有提示,第二下就提示 反复点同样,奇数不提示,偶数提示。 这个正则表达式算通过还是不通过? 在IE下怎么点都不提示的。 |
|
1楼#
发布于:2008-04-19 15:40
Remove 'g' flag from your pattern.
If your regular expression uses the "g" flag, you can use the exec method multiple times to find successive matches in the same string. When you do so, the search starts at the substring of str specified by the regular expression's lastIndex property. For example, assume you have this script:var myRe = /ab*/g; var str = "abbcdefabh"; var myArray; while ((myArray = myRe.exec(str)) != null) { var msg = "Found " + myArray[0] + ". "; msg += "Next match starts at " + myRe.lastIndex; print(msg); } |
|