Examples of Regular Expressions

This example doesn't seem to work!

The Change event activated when the user presses Enter sets the value of RegExp.input.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
      var re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;

      function testInfo(phoneInput)
        var OK = re.exec(phoneInput.value);

        if (!OK)
          window.alert(RegExp.input + " isn't a phone number with area code!");
          window.alert("Thanks, your phone number is " + OK[0]);

    <p>Enter your phone number (with area code) and then press Enter.</p>
    <form action="">
      <input name="phone" onchange="testInfo(this);">

--Jomel 19:07, 26 October 2006 (PDT)

Well, it works with (123)-456-78. I agree we could do with a better example. --Nickolay 23:28, 26 October 2006 (PDT)