Can we replace the string pattern @"^[a-zA-Z''-'\s]{1,40}$" to use as a variable in an attribute?
I tried setting the pattern to a string, but when I use [RegularExpression...] to use the variable it doesn't work. I want to use a variable since it's the same regex Format.
private static String regexFormat = @"^[a-zA-Z''-'\s]{1,40}$";
or
private static String regexFormat = "^[a-zA-Z''-'\s]{1,40}$";
[Display(Name = "Name", Description = "First Name + Last Name.")]
[Required(ErrorMessage = "First Name is required.")]
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$", ErrorMessage =
"Numbers and special characters are not allowed in the name.")]
[Required(ErrorMessage = "Last Name is required.")]
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$", ErrorMessage =
"Numbers and special characters are not allowed in the name.")]
I want something like this
[RegularExpression(regexFormat, ErrorMessage ="Error in Format")]
is this possible, if so how?