RegularExpression Attribute - Passing in a property field of a class
asp.net-mvc, attributes, c#, regex, validation
Solution
You can do something like:
[RegularExpression("^(07(\\d ?){9})", ErrorMessage = "Invalid Phone Number")]
Problem
I have created a class MobileNumberAnnotation that has a property which specifies the regex expression. Now that when I specify the RegularExpressionAttribute how do I tell it to get the value of this property as the pattern? ``` public class MobileNumberAnnotation { public string MobileFormat = "^(07(\\d ?){9})"; } ``` I tried doing the following but I don't know why it doesn't work as it is expecting a a string pattern. ``` [Required] [RegularExpressionAttribute(MobileNumberAnnotation.MobileFormat)] public int MobileNumber { get; set; } ```