I said:

> <codeSnippet language="ECMAScript">
> function RegularExpressionValidatorEvaluateIsValid(val) {
>     var value = ValidatorGetValue(val.controltovalidate);
>     if (ValidatorTrim(value).length == 0)
>         return true;
>     var rx = new RegExp(val.validationexpression);
>     var matches = rx.exec(value);
>     return (matches != null && value == matches[0]);
> }
> </codeSnippet>
>
> Your problem is that you need to set *an option*.

Actually, I take that back. You don't need to set an option for the test to
succeed... thought you might have needed global or multiline, but you don't.
I'm actually perplexed at this point because I can't figure out a piece of
their code... specifically the value == matches[0] portion.

Let's say you have a value of in the control you're validating "33\r\n33"
and your regex is "33". Stepping through their code, the exec actually
succeeds so matches != null. However, value == matches[0] only ever going to
be true if the whole string is a match! Ahhhhhhhhhaaaaaaaaaaa! So it looks
like this code can't do a portioned match which is absolutely insane. Here's
a quick ECMAScript windows script to prove the case:

<codeSnippet language="ECMAScript">
var value = "anything 33 anything";

var regex = new RegExp("33");
var matches = regex.exec(value);

WScript.Echo(matches[0]);
WScript.Echo(value == matches[0]);
</codeSnippet>

So basically what this means is you need to make your regex ".*33.*" and
everything will be good to go! Why the hell they added the value ==
matches[0] makes no sense to me as matches[0] != null would have covered all
the bases as far as I can see. Also, they could have just used RegExp::test
instead of RegExp:: exec and avoided these problems altogether.

HTH,
Drew
.NET MVP

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to