Closed Bug 339687 Opened 18 years ago Closed 18 years ago

Regular expression test evaluates false once and then true for the same test

Categories

(SeaMonkey :: General, defect)

x86
Windows XP
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 98409

People

(Reporter: carlosi, Unassigned)

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3 When using test on a regular expression that tries to determine if a numeric value is valid or not, the test returns true the first time and false the second time, even when doing the same test on the same value. Reproducible: Always Steps to Reproduce: 1. Create a regular expression object as follows: regExp = /^-{0,1}\d*\.{0,1}\d+$/g; 2. execute at least twice and check the return of the test: regExp.test(50); 3. Actual Results: It first evaluates to true and then to false Expected Results: It should have evaluated to true both times. You could create the following html file and open it with Mozilla to see the error: ------------------ HTML File begins here -------------------- <html> <head> <title>Regular expression bug</title> <script type="text/javascript"> function isDecimal(number) { var regExp = /^-{0,1}\d*\.{0,1}\d+$/g; return regExp.test(number); } for (var i = 0; i < 2; i++) { if (!isDecimal(50)) alert('If this shows up, we have a bug'); else alert('We should always get this message'); } </script> </head> <body> This page shows a Mozilla bug found when testing values using regular expressions </body> </html>
Actually, the JS Engine behaves like the ECMA spec describes it. Remove the /g from your regular expression and it should work like you want it. *** This bug has been marked as a duplicate of 98409 ***
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.

Attachment

General

Created:
Updated:
Size: