Closed
Bug 446182
Opened 18 years ago
Closed 18 years ago
Regex Result Changes Indeterminately When Fired on KeyUp Event
Categories
(Firefox :: General, defect)
Tracking
()
People
(Reporter: mail, Unassigned)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Whilst building a password strength meter that updates on the keyup event for a password form field, I found that the result of a RegExp object's test() method seems to be indeterminate when the test string is the value of the password form field.
I'm not sure what's going on here but I've produced a very simple test case that can easily demonstrate the problem.
Reproducible: Always
Steps to Reproduce:
1. Create a page using the following code:
<html>
<body>
<input type="text" id="foo" onkeyup="javascript:document.getElementById('bar').value = hasDigits(this.value);" />
<input type="text" id="bar" />
<script type="text/javascript">
function hasDigits(p) {
return /\d/g.test(p);
}
</script>
</body>
</html>
2. Type a digit, say, "8" in the first box, and then type a single letter, say, "e" several times after the "8".
3. Observe the result of the function, which is placed in the second text box.
Actual Results:
With each successive "e" character, the result will alternate true/false.
Expected Results:
The result should very clearly always be true - the regex pattern is looking for any match on a digit and there is always one at the start.
By placing a breakpoint on the return line in the function and copying the expression that is returned into the Firebug Console and executing it, the value ALWAYS returns true, but when I step past that same line of code, it returns false.
Opera also exhibits this unusual behaviour, but Internet Explorer and Safari do not.
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•