【发布时间】:2021-04-21 05:43:58
【问题描述】:
RegularExpressionAttribute (System.ComponentModel.DataAnnotations) 如何处理从 .NET 正则表达式模式风格到 javascript 风格的转换,以便在客户端进行验证?
我猜根本没有翻译,属性中指明的正则表达式模式必须与两个引擎都足够兼容。
谢谢
【问题讨论】:
标签: .net regex asp.net-mvc data-annotations
RegularExpressionAttribute (System.ComponentModel.DataAnnotations) 如何处理从 .NET 正则表达式模式风格到 javascript 风格的转换,以便在客户端进行验证?
我猜根本没有翻译,属性中指明的正则表达式模式必须与两个引擎都足够兼容。
谢谢
【问题讨论】:
标签: .net regex asp.net-mvc data-annotations
您的猜测是正确的,正则表达式没有被以任何方式翻译,只是直接传递给客户端。这可以通过检查RegularExpressionAttributeAdapter 和ModelClientValidationRegexRule 类的源代码轻松验证。
您可以查看以下问题以获取有关 C# 和 JavaScript 正则表达式引擎之间差异的更多信息:Differences between C# and JavaScript Regular Expressions
【讨论】:
现在 CodePlex 已关闭,请尝试在 github 上查看源代码:RegularExpressionAttributeAdapter 和 ModelClientValidationRegexRule.
【讨论】: