regular expression

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
  <title>Project 5 Test</title>
  <script language="JavaScript">

function SymError()
  return true;

window.onerror = SymError;

var SymRealWinOpen =;

function SymWinOpen(url, name, attributes)
  return (new Object());
} = SymWinOpen;

  <script language="JavaScript"><!--
      function do_update() {
        var tx = document.myform.mytext.value;
        var re = /[0-9]/;
        if (tx.match(re))
          document.bgColor = "lightgreen";
          document.bgColor = "pink";

<body onkeyup="do_update()">
<form name="myform">
  <p><input type="text" size="60" name="mytext"> <br>
Test Text </p>
<script language="JavaScript">
<!-- = SymRealWinOpen;

i want to make all number with 2 digits valid, but
why it keeps green if i type more than 2 digits?

thanks in advance

Re: regular expression

Joseph Wu wrote:
Quoted text here. Click to load it
If you don't anchor a regex to the start and end of text, it will match
if the text contains the pattern. Try changing it to this:
         var re = /^[0-9]$/;

Re: regular expression

Quoted text here. Click to load it

thank you very much , it works !

Site Timeline