comments inline

On Wed, 15 May 2002 19:05:21 -0400, Marsh, Drew <[EMAIL PROTECTED]> wrote:

>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.

What you're saying makes sense.  I originally thought that the regex val
control should match the whole text, but now I can't see why you shouldn't
have the option to match it all, or a portion of it?  Either approach is
valid:  it's up to the developer to work out which technique is good enough
to make data is valid.

>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.
>

I tried the .*33.* in a multiline textarea, and it worked ok if "33" was on
the first row but, not if 33 was on the 2nd ie aa\r\n33.

I've also had trouble applying options.  eg

/IN/i

I could not make it work in either a single or multiline scenario, either
lower or upper case.  This is my intepretation of the help, so it may be
off.

Thanks for the other reply too, Drew!

>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.

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