Dmitry Korolyov [MVP] wrote:[color=blue]
> That's warmer Mike. But regexplib website shows us absolutely correct
> behavior - or do they use custom handling?
>[/color]
There's extra code in the handling of the RegularExpressionValidator.
Pseudo-code looks something like:
string len = controlToValidate.Text.Length;
if (len == 0) {
// nothing in the control - automatically validated
return( true);
}
Match m = regex.Match( controlToValidate.Text);
if (m.Success && (m.Length == len)) {
return( true);
}
return( false);
[color=blue]
> --
> Dmitry Korolyov [d__k@removethispart.mail.ru]
> MVP: Windows Server - Active Directory
>
>
>
> "mikeb" <mailbox.google@mailnull.com
> <mailto:mailbox.google@mailnull.com>> wrote in message
> news:OVr5Tc2kDHA.1084@tk2msftngp13.phx.gbl...
> Dmitry Korolyov [MVP] wrote:[color=green]
> > Thanks Steve.
> >
> > 1) Why the first example works the opposite (to what I see and[/color]
> what you[color=green]
> > have explained) at
www.regexplib.com <http://www.regexplib.com>[/color]
> <http://www.regexplib.com> ? They[color=green]
> > have set up a testing area where you can test various regexps and[/color]
> see if[color=green]
> > they match or not the strings you enter.
> >[/color]
>
> The RegularExpressionValidator is documented to succeed if the input
> control is empty (ie., the Regexp is not even run in this case). That
> might not be intuitive for you, but it's how MS decided it should work.
>[color=green]
> > 2) \d+ means one or more digits. They can be anywhere within the[/color]
> string.[color=green]
> > This means "g2323" should match the regular expression, but it[/color]
> doesn't[color=green]
> > (although it does on the testing area of
> > <http://www.regexplib.com>
www.regexplib.com[/color]
> <http://www.regexplib.com> <http://www.regexplib.com>[color=green]
> > and in any other regexp-compatible language). Note that if I[/color]
> wanted a[color=green]
> > string which contains digits only, I'd use ^\d+$ regexp.
> >
> > So I guess there should be some more ideas...[/color]
>
> Looking at the IL for the RegularExpressionValidator, it appears
> that MS
> made an undocumented decision such that it will return a successful
> validation only when the regex matches the entire contents of the
> control.
>
> I'd agree with you that this is counter-intuitive, and it appears to be
> undocumented. I'm not sure whether MS would consider this a bug in
> implementation or a bug in documentation. In any case, the behavior
> exists in both current versions of the Framework (1.0 SP2 and 1.1).
>
> So, if you want your Regex's to match with the behavior that MS
> hard-coded for RegularExpressionValidator, the ValidationExpression
> should always be bounded by the ^ and $ characters.
>[color=green]
> >
> > P.S. I'm still thinking of the different versions of the framework.
> >
> > --
> > Dmitry Korolyov [d__k@removethispart.mail.ru]
> > MVP: Windows Server - Active Directory
> >
> >
> >
> > "Steve Jansen" <stj3570@dev.nul <mailto:stj3570@dev.nul>[/color]
> <mailto:stj3570@dev.nul>> wrote in[color=green]
> > message news:uvpTXC0kDHA.2528@TK2MSFTNGP10.phx.gbl...
> > Per MSDN on the RegularExpressionValidatorControl:
> >
> > "Note: Validation succeeds if the input control is empty. If a
> > value is
> > required for the associated input control, use a[/color]
> RequiredFieldValidator[color=green]
> > control in addition to the RegularExpressionValidator control."
> >
> > This is why it appears ^\d+$ is matched with an empty string.
> >
> > Also, "d+" means match one or more "d" characters, which is[/color]
> why it[color=green]
> > does not
> > match "g24". You probably intended "^\w+$", meaning a[/color]
> single line[color=green]
> > string
> > with only alphanumerics [a-zA-Z_0-9].
> >
> > -Steve Jansen
> >
> > ---------------------------
> > "Dmitry Korolyov" <d__k@removethispart.mail.ru[/color]
> <mailto:d__k@removethispart.mail.ru>[color=green]
> > <mailto:d__k@removethispart.mail.ru>> wrote in message
> > news:%23iqDSlzkDHA.964@TK2MSFTNGP10.phx.gbl...
> > ASP.NET app using c# and framework version 1.1.4322.573 on a[/color]
> IIS 6.0 web[color=green]
> > server.
> >
> > A single-line asp:textbox control and regexp validator[/color]
> attached to it.[color=green]
> >
> > ^\d+$ expression does match an empty string (when you don't
> > enter any
> > values) - this is wrong
> > d+ expression does not match, for example "g24"[/color]
> string - this is[color=green]
> > also wrong
> >
> >
www.regexplib.com <http://www.regexplib.com>[/color]
> <http://www.regexplib.com> test validator works[color=green]
> > fine for both cases, i.e. it is
> > reporting "not match" for the first one and "match" for the[/color]
> second[color=green]
> > one. I am
> > suspecting using different framework version from regexplib, and
> > this being
> > the source of the error. Do you have any other ideas?
> >
> > --
> > Dmitry Korolyov [d__k@removethispart.mail.ru]
> > MVP: Windows Server - Active Directory
> >[/color]
>
> --
> mikeb[/color]
--
mikeb