RegularExpression field validation
Regular expression validation is the only solution used for most validations such as email, phone number, zip code, username, password, and so on. Most of the patterns used with regular expressions are wrapped into separate validations. Still, the usage is vast and requires a method to define custom validation. That's where RegularExpression
 validation comes in handy. Lets investigate regular expressions in this section.
If the field value doesn't follow the defined regular expression pattern, then a validation error would be returned by the engine. For instance, if the regular expression is configured to contain only letters of the alphabet, then any other character inclusion would throw a validation error.
The RegularExpression
attribute/data annotation can be configured as follows:
public class Person { public int Id { get; set; } [Required(ErrorMessage = "First Name is required")] [RegularExpression("^[a-zA-Z]+$")] public...