0
我已经创建了一个MobileNumberAnnotation类,它具有指定正则表达式的属性。现在,当我指定RegularExpressionAttribute时,我如何告诉它将该属性的值作为模式获取?RegularExpression属性 - 传入一个类的属性字段
public class MobileNumberAnnotation
{
public string MobileFormat = "^(07(\\d ?){9})";
}
我试着做了以下,但我不知道为什么它不工作,因为它期待一个字符串模式。
[Required]
[RegularExpressionAttribute(MobileNumberAnnotation.MobileFormat)]
public int MobileNumber { get; set; }
*假设你正确输入你的正则表达式。 –
我知道你可以做到这一点。不过谢谢你的帮助 – user1781232