Is it possible with DataAnnotation s and regular expressions to filter an entry in the text box ? ie To trigger an invalid response when the word "apt" is in the string ?
Yes you can do that using negative look-arounds, like this:
public class MyModel
{
[RegularExpression(@"^((?!apt).)*$", ErrorMessage = "You can not have that")]
public string MyValue { get; set; }
}
Here is a good reference question for these types of regular expressions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.