只有 n 个字符的数据注释

Data Annotations for only n character

是否有仅 n 个字符的数据注释类型。我不想使用 StringLength、maxlength 和 minlength。例如,

[DataAnnotationName (ErrorMessage="{0} field must be 10 characters")]
public string SecurtyCode { get; set; }

您可以使用 RegularExpression 属性:

[RegularExpression(@".{10}", ErrorMessage = "{0} field must be 10 characters")]
public string Bar { get; set; }