在我的MVC 4应用程序中,我需要在帐户注册屏幕上进行验证;密码包含至少1位数,1个大写& 1个小写字符。我希望模型类属性类似于
[Display(Name = "Register_Password", ResourceType = typeof(VirtuOxAdmin))]
[Required(ErrorMessageResourceType = typeof(VirtuOxAdmin), ErrorMessageResourceName = "Register_PasswordRequired")]
[MinLength(5, ErrorMessageResourceType = typeof(VirtuOxAdmin), ErrorMessageResourceName = "Admin_CreateCustomer_PasswordMinLength")]
[MaxLength(32, ErrorMessageResourceType = typeof(VirtuOxAdmin), ErrorMessageResourceName = "Admin_CreateCustomer_PasswordMaxLength")]
[RegularExpression(@"\d", ErrorMessageResourceType = typeof(VirtuOxAdmin), ErrorMessageResourceName = "Admin_CreateCustomer_AtleastOneDigit")]
[RegularExpression("[A-Z]+", ErrorMessageResourceType = typeof(VirtuOxAdmin), ErrorMessageResourceName = "Admin_CreateCustomer_AtleastOneUChar")]
[RegularExpression("[a-z]+", ErrorMessageResourceType = typeof(VirtuOxAdmin), ErrorMessageResourceName = "Admin_CreateCustomer_AtleastOneLChar")]
public string Password { set; get; }
但我收到错误错误重复'RegularExpression'属性
我如何编码密码验证?
答案 0 :(得分:2)
您必须将所有元素组合成一个正则表达式。为此,您可以使用零宽度预测断言。这样的事情应该有效:
(?=.*[a-z])(?=.*[A-Z])(?=.*\d)