DataAnnotation 是否可行? s 和正则表达式来过滤文本框中的条目?即当字符串中包含单词“apt”时触发无效响应?
最佳答案
是的,你可以使用负面环视来做到这一点,就像这样:
public class MyModel
{
[RegularExpression(@"^((?!apt).)*$", ErrorMessage = "You can not have that")]
public string MyValue { get; set; }
}
对于这些类型的正则表达式,这是一个很好的引用问题。
关于c# - 将 DataAnnotations 与正则表达式一起使用以不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18218701/