I've been tearing my hair out over this one, and it appears to be a bug in Mozilla's regular expression engine. If I run the same re test over the same data in IE I get the same result every time, just as you would expect. BUT, if I do the same thing in FireFox I get alternating True and False results when the data matches the regular expression (it works fine if the data doesn't match the re). Here's the code I set up to demonstrate the problem:
If you don't want to type it in, use this link.
Try it in both IE and FF. Click the test button repeatedly. In IE it will yield correct results. In FF it will alternate between True and False when the value is valid (but stay false when the value is invalid).
Any explanation?
Tracy Dryden
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.![[dragon] [dragon] [dragon]](/data/assets/smilies/dragon.gif)
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html>
<head>
<title>Test RE</title>
<script type="text/javascript">
function testit() {
if ( /^\d{3}$/g.test(document.forms['daform'].elements['danum'].value) ) {
document.getElementById('daresult').innerHTML = "TRUE";
} else {
document.getElementById('daresult').innerHTML = "FALSE";
}
}
</script>
</head>
<body>
<form name="daform">
<input type="text" name="danum" id="danum" value="123" />
<input type="button" name="dabutton" value="TEST" onclick="testit();">
(Three Digits)
</form>
<span id="daresult" style="font-weight:bold;"> </span>
</body>
</html>
Try it in both IE and FF. Click the test button repeatedly. In IE it will yield correct results. In FF it will alternate between True and False when the value is valid (but stay false when the value is invalid).
Any explanation?
Tracy Dryden
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
![[dragon] [dragon] [dragon]](/data/assets/smilies/dragon.gif)