我在MVC4中使用数据注释进行模型验证,并且当前使用StringLengthAttribute,但是我不想指定最大值(当前设置为50),但是要指定最小值字符串长度值。DataAnnotations StringLength属性MVC - 没有最大值
有没有办法只指定最小长度?也许我可以使用另一个属性?
我当前的代码是:
[Required]
[DataType(DataType.Password)]
[Display(Name = "Confirm New Password")]
[StringLength(50, MinimumLength = 7)]
[CompareAttribute("NewPassword", ErrorMessage = "The New Password and Confirm New Password fields did not match.")]
public string ConfirmNewPassword { get; set; }
任何帮助深表感谢。
感谢Leniel。正如你所建议的那样,我使用正则表达式来控制字符串长度。 – davey1990 2012-07-10 00:15:28