I am inheriting the RegularExpressionAttribute to create my own DataAnnotation for validating user input. It is not working for me.
I wish to only allow hyphens, spaces and upper/lowercase letters.
Regardless of what I input into the form on the MVC Web App, it shows the error message each time.
What am I doing wrong?
The custom DataAnnotation from the class is [NameValidation]
Code:public class NameValidationAttribute : RegularExpressionAttribute { public NameValidationAttribute() : base(@"/^[a-zA-Z \-]+$/") { ErrorMessage = "{0} can only consist of letters and spaces. Please correct your input."; } }




Reply With Quote