我在ASP.NET MVC 4項目中使用FluentValidation框架進行服務器端和客戶端驗證。只應驗證最小/最大長度
是否有原生(非黑客)的方式來驗證字符串長度只有最大長度,或只有最小長度?
例如這樣:
var isMinLengthOnly = true;
var minLength = 10;
RuleFor(m => m.Name)
.NotEmpty().WithMessage("Name required")
.Length(minLength, isMinLengthOnly);
默認的錯誤信息模板應不
'Name' must be between 10 and 99999999 characters. You entered 251 characters.
但
'Name' must be longer 10 characters. You entered 251 characters.
和客戶端的屬性應該是suppo例如,像RuleFor(m => m.Name.Length).GreaterThanOrEqual(minLength)
(不知道它是否有效)不適用。