Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > regular expression

Reply
Thread Tools

regular expression

 
 
Joseph Wu
Guest
Posts: n/a
 
      08-31-2003
<html>
<head>
<title>Project 5 Test</title>
<style><!--
body{font-size:18}
input{font-size:24}
--></style>
<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

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

window.open = SymWinOpen;

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

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

window.open = SymRealWinOpen;

//-->
</script>
</body>
</html>
-----------------------------------------------------------
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
 
Reply With Quote
 
 
 
 
Leif K-Brooks
Guest
Posts: n/a
 
      08-31-2003
Joseph Wu wrote:
> i want to make all number with 2 digits valid, but
> why it keeps green if i type more than 2 digits?

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]{1,2}$/;


 
Reply With Quote
 
 
 
 
Joseph Wu
Guest
Posts: n/a
 
      08-31-2003
Leif K-Brooks <(E-Mail Removed)> wrote in
news:OUd4b.479$(E-Mail Removed)2.webusenet.com:

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

> 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]{1,2}$/;
>
>


thank you very much , it works !
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments