ASP.NET Core Web API - How to merge two Regular Expressions as one using data annotation

Viewed 16

In ASP.NET Core-6 Web API, I am implementing Regular Expressions for validation using data annotation:

[Required(ErrorMessage = "First Name field is required. ERROR!")]
[StringLength(25, MinimumLength = 2, ErrorMessage = "First Name field should be at least 2 characters long, but not longer than 25 characters.")]
[RegularExpression(@"^[\S]+$", ErrorMessage = "No Space Required in First Name field")]
[RegularExpression("[A-Za-z]", ErrorMessage = "First Name field can only contain alphabets")]
public string FirstName { get; set; }

I got an error for duplicate RegularExpression.

How do I resolve this or merge the two Regular Expressions as one?

Thanks

0 Answers
Related