这是我的正则表达式:
[RegularExpression(@"^((?=.{12,}$)(?=[^\d]*\d)(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=[^\W]*\W))", ErrorMessage = "Passwords must be at least 12 characters long and contain at least an upper case letter, lower case letter, digit and a symbol")]
条件:
12个字符长,至少包含一个小写字母,大写字母和特殊字符。
在以下情况下字符串被拒绝
:任何少于12个字符的字符串,
aaaaaaaaaaaaaa
aaaaaaaaaaaaaa1
在以下情况下接受(应拒绝)字符串:
aaaaaaaaaaaaaaA
aaaaaaaaaaaaaa#
编辑:这是我用于模型中密码获取和设置程序的代码。
[Required]
[RegularExpression("^(?=.{12,}$)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[$@!%*?&,#]).+$", ErrorMessage = "Passwords must be at least 12 characters long and contain at least an upper case letter, lower case letter, digit and a symbol")]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
答案 0 :(得分:0)
尝试一下:
您的条件:
12个字符长,至少包含一个小写字母,大写字母和特殊字符。
注意:我也添加了一个数字,因为您的验证消息中包含数字。
team member
答案 1 :(得分:0)
[RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{12,}", ErrorMessage = "Passwords must be at least 12 characters long and contain at least an upper case letter, lower case letter, digit and a symbol")]
@SwapNeil给出的答案是正确的。
您可以在这里尝试:https://regex101.com/
如果仍然无法正常工作。请检查视图中是否包含〜/ bundles / jqueryval。