代码如下:
[Required(ErrorMessage = "密码不能为空"), RegularExpression(@"^(?=.*d)(?=.*[a-z]).{6,18}$", ErrorMessage = "必须包含小字母和数字")] [StringLength(100, ErrorMessage = "{0} 至少包含 {2} 个字符。", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "密码")] public string Password { get; set; }