Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以使用DataAnnotation和正则表达式来过滤文本框中的条目?即当“apt”一词在字符串中时触发无效响应?
是的,您可以使用负面环视来做到这一点,如下所示:
public class MyModel { [RegularExpression(@"^((?!apt).)*$", ErrorMessage = "You can not have that")] public string MyValue { get; set; } }
对于这些类型的正则表达式,这是一个很好的参考问题。
正则表达式匹配不包含单词的字符串?