* ad wrote, On 19-7-2006 23:52:
Quote:
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