- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
The Gu provides an example介绍如何创建覆盖 RegularExpressionAttribute 的自定义验证器。
这样做的好处是你不必create a custom Model Validator但我无法让它工作。
给出以下代码:
public class NameAttribute : RegularExpressionAttribute {
public NameAttribute()
: base(@"^[\w\s\-\']+$") {
}
}
这有效:
[RegularExpression(@"^[\w\s\-\']+$")]
但这不是:
[Name]
我是否误解了 Scott 示例的某个方面,或者该示例是否有缺陷,因为 MVC 不支持开箱即用的派生类型,所以实际上我必须创建一个相应的 ModelValidator?
最佳答案
破解了!将以下内容添加到 Global.asax.cs Application_Start()
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(NameAttribute), typeof(RegularExpressionAttributeAdapter));
关于asp.net-mvc - 派生自 RegularExpressionAttribute 的自定义 DataAnnotations 验证器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2689444/
我有一个用于客户端验证的字符串: private const String regex = @"^(?:\b(?:\d{5}(?:\s*-\s*\d{5})?|([A-Z]{2})\d{3}(?:\s
我需要验证的只是一个小数点(或一个点)。 我使用了以下正则表达式: "\.+" 我用 .NET 编译器和 JS 测试器进行了测试,表达式似乎是有效的。 我在模型中有以下属性: [RegularExpr
我正在使用这个正则表达式:@"[ \]\[;\/\\\?:*""<>|+=]|^[.]|[.]$" 第一部分[ \]\[;\/\\\?:*""<>|+=]应匹配括号内的任何字符。 下一部分 ^[.]如
我有以下代码来测试类属性: public class RegExtTest { [RegularExpression(@"^[A-z0-9]{6}$", ErrorMessage = "Lot
public class City { [DynamicReqularExpressionAttribute(PatternProperty = "RegEx")] public stri
我无法对使用 MVC3RTM 的正则表达式进行客户端验证。当我注释掉 RegularExpression 属性时,所有其他客户端验证都有效,所以我知道这是导致我出现问题的原因。 我有一个简单的模型。
我正在使用 RegularExpressionAttribute 来验证属性。该属性需要允许除零长度字符串、null 或(仅)空格之外的任何内容。我使用的正则表达式是 "^(?!^ *$)^.+$".
我需要一个匹配包含“[S]”的文本的正则表达式模式。我试过这样的事情: ^(?\\[S\\]$)$ 但它不起作用。我怎样才能做到这一点? 编辑: 正则表达式的目的是将其用作客户端验证中的正则表达式:
我们为 MVC3 应用程序编写自定义 RegularExpressionAttribute。自定义 RegularExpressionAttribute 的目的是,我们想用关键字替换资源文件消息中的
我使用 RegularExpressionAttribute像这样在我的 EF 元数据上: [RegularExpression("[A-Z]+")] public string Code { get
为了保持我的模型验证干净,我想实现我自己的验证属性,比如 PhoneNumberAttribute和 EmailAttribute .其中一些可以有利地实现为从RegularExpressionAtt
The Gu provides an example介绍如何创建覆盖 RegularExpressionAttribute 的自定义验证器。 这样做的好处是你不必create a custom Mod
我是一名优秀的程序员,十分优秀!