I there a way in ASP.Net MVC to have a RegularExpression attribute on a model property to pull the pattern string property from resource file or another class?
When I attempt to use another class I get a message stating that the attribute values must be a constant, typeof expression, or an array.
Ultimately, I’m attempting to abstract some of these patterns so I don’t have to update multiple files if a bug is located in a pattern.
Example:
public class MyModel{
[RegularExpression(StaticPatternClass.EmailPattern, ErrorMessage="invalid email")]
public string email { get; set;}
}
public static class StaticPatternClass{
public static string EmailPattern = @"My pattern here";
}
Try
public const string EmailPattern ….
instead