0

How does RegularExpressionAttribute (System.ComponentModel.DataAnnotations) handle the translation from .NET Regular Expression pattern flavor to the javascript flavor in order to do the validations client-side?

I'm guessing that there is no translation at all, and the regular expression pattern indicated in the attribute must be compatible enough with both engines.

Thanks

4

2 回答 2

3

Your guess is correct, the regular expression is not being translated in any way, just being directly passed to the client side. This can be easly verified by checking the source code of RegularExpressionAttributeAdapter and ModelClientValidationRegexRule classes.

You can check the following question for more informations about differences between C# and JavaScript Regular Expressions engines: Differences between C# and JavaScript Regular Expressions

于 2013-02-01T08:22:09.757 回答
0

Now that CodePlex has been shut down, try viewing sources on github: RegularExpressionAttributeAdapter and ModelClientValidationRegexRule.

于 2021-04-20T21:43:58.480 回答