Regex bug in Javascript when you try to test

RESOLVED DUPLICATE of bug 98409

Status

()

Firefox
General
RESOLVED DUPLICATE of bug 98409
12 years ago
12 years ago

People

(Reporter: Egri Attila, Unassigned)

Tracking

1.5.0.x Branch
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

12 years ago
User-Agent:       Pntools application
Build Identifier: Firefox/1.5.0.1

When you try to test a string (that it is a number or not) for example "a1" with regex.test() and on first run you get "false", and on secound then you get "true".

Reproducible: Always

Steps to Reproduce:
Use this HTML/Javascript code:
<html>
<head>
<title>Firefox regex bug</title>
<script>
function isANumber() {
    var value = document.getElementById("inputID").value;

    var re = null;
    re = /[\D]/g;

    if (re.test(value)) alert("false");
    else alert("true");
}
</script>
</head>

<body>
    <input id="inputID" type="text" value="" />
    <input type="button" value="Test the value" onClick="isANumber();" />
</body>
</html>
Actual Results:  
Type "a1" to the text field and you press the button then you get "false" (NaN), and you press again then you get "true" (number)

Expected Results:  
False value everytime
(Reporter)

Updated

12 years ago
Version: unspecified → 1.5.0.x Branch

Comment 1

12 years ago
This behavior is caused by the 'g' flag in your RegExp and is working as specified.

*** This bug has been marked as a duplicate of 98409 ***
Status: UNCONFIRMED → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.