Kirk Jackson [mailto:[EMAIL PROTECTED]] wrote:

> Yeah, I've found that the Jscript regular expressions (client
> side) don't support all of the syntax of the C# regular
> expressions (when a regex validator does a validate on the
> server side).
>
> I ended up having to turn off client-side validation in a
> couple of places, and in other places I split the regular
> expressions out into 2 separate validators.

ECMAScript regexes are different from .NET regexes. You're actually warned
about this by this snippet found here[1] in the SDK:

<snip>
The regular expression validation implementation is slightly different on
the client than on the server. On the client, JScript regular expression
syntax is used. On the server, System.Text.RegularExpressions.Regex syntax
is used. Since JScript regular expression syntax is a subset of
System.Text.RegularExpressions.Regex syntax, it is recommended that JScript
regular expression syntax be used in order to yield the same results on both
the client and the server.
</span>

Unfortunately they don't say how they differ, but I ripped this out of the
WebValidationUI.js supplied by the ASP.NET client runtime:

<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*. Option setting within a
regex expression is different within ECMAScript and .NET and unfortunately
are not interchangeable in the least. In .NET you use "(?options)expression"
in JScript you use "/expression/options". Unfortunately they don't provide
an options property on the validator control (probably because it would have
been quite difficult) so you pretty much have to choose between one syntax
or the other depending on where you want it to run.

HTH,
Drew
.NET MVP

[1]
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemWebUIWebControlsRegularExp
ressionValidatorClassTopic.htm

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