我在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