Talk:Core JavaScript 1.5 Guide:Working with Regular Expressions:Examples of Regular Expressions
From MDC
This example doesn't seem to work!
TheChangeevent activated when the user presses Enter sets the value ofRegExp.input.<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <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!"); } else { window.alert("Thanks, your phone number is " + OK[0]); } } </script> </head> <body> <p>Enter your phone number (with area code) and then press Enter.</p> <form action=""> <input name="phone" onchange="testInfo(this);"> </form> </body> </html>
--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)