I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressionValidator and Regex class to
validate a value.
The RegularExpress is 20|\-9|\-1|[1]?\d{1}
When I enter 33 and validate with RegularExpressionValidator, it fail to
pass.
But when I validate with regex class :
Regex.IsMatch(Sight0L, @"20|\-9|\-1|[1]?\d{1}");
it passed!!
Why, the results are different? 4 2785
* ad wrote, On 19-7-2006 23:52:
I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressionValidator and Regex class to
validate a value.
The RegularExpress is 20|\-9|\-1|[1]?\d{1}
When I enter 33 and validate with RegularExpressionValidator, it fail to
pass.
But when I validate with regex class :
Regex.IsMatch(Sight0L, @"20|\-9|\-1|[1]?\d{1}");
it passed!!
Why, the results are different?
RegEx.IsMatch uses the .Net regular expression library while the
clientside validator will use the Javascript library. You should be able
to simulate the Javascriptlibary by setting the RegexOptions.ECMAScript
Regex.IsMatch(Sight0L, @"20|\-9|\-1|[1]?\d{1}", RegexOptions.ECMAScript);
Note that your regex contains a few errors that might be causing this:
(20|-9|-1|1?\d) is probably closer to your needs.
Note that:
'-' is no special character except in character classes (between [ and
]) so no escaping is needed here
[1] is the same as 1, so you can lose the [ and ].
\d{1} is the same as \d, so you can lose the {1}.
It is best to add ( and ) when you're using the '|'.
With these changes both libraries should give the same result.
Jesse Houwing
Thanks,
My intention of RegularExpress is to test a integer value, if the value :
if ((iSight<=20 && iSight>=0) | (iSight==-1 | iSight==-9)) then pass
When I test with value 44,
My 20|\-9|\-1|[1]?\d{1} will faill when use RegularExpressionValidator but
passed with Regex class.
I have tried the regular expressin you mentioned about, but it is passed too
when when with Regex class.
"Jesse Houwing" <je***********@nospam-sogeti.nl>
???????:e4**************@TK2MSFTNGP05.phx.gbl...
>* ad wrote, On 19-7-2006 23:52:
>I am useing VS2005 to develop wep application. I use a RegularExpress both in RegularExpressionValidator and Regex class to validate a value. The RegularExpress is 20|\-9|\-1|[1]?\d{1} When I enter 33 and validate with RegularExpressionValidator, it fail to pass. But when I validate with regex class : Regex.IsMatch(Sight0L, @"20|\-9|\-1|[1]?\d{1}");
it passed!!
Why, the results are different?
RegEx.IsMatch uses the .Net regular expression library while the
clientside validator will use the Javascript library. You should be able
to simulate the Javascriptlibary by setting the RegexOptions.ECMAScript
Regex.IsMatch(Sight0L, @"20|\-9|\-1|[1]?\d{1}", RegexOptions.ECMAScript);
Note that your regex contains a few errors that might be causing this:
(20|-9|-1|1?\d) is probably closer to your needs.
Note that:
'-' is no special character except in character classes (between [ and ])
so no escaping is needed here
[1] is the same as 1, so you can lose the [ and ].
\d{1} is the same as \d, so you can lose the {1}.
It is best to add ( and ) when you're using the '|'.
With these changes both libraries should give the same result.
Jesse Houwing
* ad wrote, On 20-7-2006 1:53:
Thanks,
My intention of RegularExpress is to test a integer value, if the value :
if ((iSight<=20 && iSight>=0) | (iSight==-1 | iSight==-9)) then pass
When I test with value 44,
My 20|\-9|\-1|[1]?\d{1} will faill when use RegularExpressionValidator but
passed with Regex class.
I have tried the regular expressin you mentioned about, but it is passed too
when when with Regex class.
Ok, just add ^ and $ to contrain the regex to the whole input like this:
bool x = Regex..IsMatch("44", @"^(20|-9|-1|1?\d)$");
It should do the trick.
>
"Jesse Houwing" <je***********@nospam-sogeti.nl>
???????:e4**************@TK2MSFTNGP05.phx.gbl...
>* ad wrote, On 19-7-2006 23:52:
>>I am useing VS2005 to develop wep application. I use a RegularExpress both in RegularExpressionValidator and Regex class to validate a value. The RegularExpress is 20|\-9|\-1|[1]?\d{1} When I enter 33 and validate with RegularExpressionValidator, it fail to pass. But when I validate with regex class : Regex.IsMatch(Sight0L, @"20|\-9|\-1|[1]?\d{1}");
it passed!!
Why, the results are different? RegEx.IsMatch uses the .Net regular expression library while the clientside validator will use the Javascript library. You should be able to simulate the Javascriptlibary by setting the RegexOptions.ECMAScript
Regex.IsMatch(Sight0L, @"20|\-9|\-1|[1]?\d{1}", RegexOptions.ECMAScript);
Note that your regex contains a few errors that might be causing this: (20|-9|-1|1?\d) is probably closer to your needs.
Note that: '-' is no special character except in character classes (between [ and ]) so no escaping is needed here
[1] is the same as 1, so you can lose the [ and ].
\d{1} is the same as \d, so you can lose the {1}.
It is best to add ( and ) when you're using the '|'.
With these changes both libraries should give the same result.
Jesse Houwing
I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressionValidator and Regex class to
validate a value.
The RegularExpress is 20|\-9|\-1|[1]?\d{1}
When I enter 33 and validate with RegularExpressionValidator, it fail to
pass.
But when I validate with regex class :
Regex.IsMatch(Sight0L, @"20|\-9|\-1|[1]?\d{1}");
it passed!!
Why, the results are different?
The RegularExpressionValidator requires the entire string to be
matched. In effect it matches against "^<your RE>$".
When you use Regex.Match, it matches on a single "3", not on the entire
string. It matches the [1]?\d{1} part, because the {1}? is optional.
Hans Kesting This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jon Maz |
last post by:
Hi All,
Am getting frustrated trying to port the following (pretty simple) function
to CSharp. The problem is that I'm lousy at Regular Expressions....
//from...
|
by: aevans1108 |
last post by:
expanding this message to microsoft.public.dotnet.xml
Greetings
Please direct me to the right group if this is an inappropriate place
to post this question. Thanks.
I want to format a...
|
by: bill tie |
last post by:
I'd appreciate it if you could advise.
1. How do I replace "\" (backslash) with anything?
2. Suppose I want to replace
(a) every occurrence of characters "a", "b", "c", "d" with "x",
(b)...
|
by: Dave |
last post by:
I'm struggling with something that should be fairly simple. I just don't
know the regext syntax very well, unfortunately.
I'd like to parse words out of what is basically a boolean search...
|
by: clintonG |
last post by:
I'm using an .aspx tool I found at but as nice as the interface is I
think I need to consider using others. Some can generate C# I understand.
Your preferences please...
<%= Clinton Gallagher
...
| |
by: jg |
last post by:
I made a mistake somewhere in my vb code and I look, check and read against
the articles and help on regex, I still can't find the mistake I made.
I know my test string and the test patterns...
|
by: Talin |
last post by:
I've run in to this problem a couple of times. Say I have a piece of
text that I want to test against a large number of regular expressions,
where a different action is taken based on which regex...
|
by: Mark Chambers |
last post by:
Hi there,
I'm seeking opinions on the use of regular expression searching. Is there
general consensus on whether it's now a best practice to rely on this rather
than rolling your own (string)...
|
by: =?Utf-8?B?amFj?= |
last post by:
Hi,
I have problems with following code and don’t find the bug :
// Set
ArrayList aArray = new ArrayList();
regStr = new Regex(@"\?)*(\d+)\]");
if(text != null && regStr.IsMatch(text))...
|
by: jonnyboy6969 |
last post by:
Hi All
Really hoping someone can help me out here with my deficient regex skills :)
I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |