– 每个验证属性的所有不显眼的验证属性的列表


enter image description here

MVC为它提供的每个数据注释验证器提供了不显眼的验证器.从Validation with Data Annotation Validators开始,这是列表:

Using the Data Annotation Validator Attributes

When you use the Data Annotations Model Binder, you use validator attributes to perform validation. The System.ComponentModel.DataAnnotations namespace includes the following validator attributes:

  • Range – Enables you to validate whether the value of a property falls
    between a specified range of values.
  • ReqularExpression – Enables you to validate whether the value of a
    property matches a specified regular expression pattern.
  • Required – Enables you to mark a property as required.
  • StringLength –
    Enables you to specify a maximum length for a string property.
  • Validation – The base class for all validator attributes.
  • DataTypeAdditional validations for specific data types, like phone numbers, credit cards and email addresses. Not in the referenced link.


正则表达式变为data-val-regex =“Message”data-val-regex-pattern =“some pattern”

来自MVC3 jQuery.validate.unobtrusive.js:

adapters.addSingleVal("accept", "exts")
        .addSingleVal("regex", "pattern");


adapters.addMinMax("length", "minlength", "maxlength", "rangelength")
        .addMinMax("range", "min", "max", "range");

adapters.add("equalto", ["other"], function (options) {
        // removed for brevity
adapters.add("required", function (options) {
    // removed for brevity
adapters.add("remote", ["url", "type", "additionalfields"], function (options) {
    // removed for brevity

转载注明原文 – 每个验证属性的所有不显眼的验证属性的列表 - 代码日志