1

在我的 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; }

但我收到错误 Error Duplicate 'RegularExpression' 属性

如何编码以进行密码验证?

4

1 回答 1

3

您必须将所有元素组合成一个正则表达式。为此,您可以使用零宽度前瞻断言。像这样的东西应该工作:

(?=.*[a-z])(?=.*[A-Z])(?=.*\d)
于 2013-11-01T11:04:06.377 回答