Inferred Rules
While you can specify your rules in the v-validate
directive, vee-validate also resolve rules for native HTML5 elements based on their constraint attributes and their type.
Example
It would be redundant to specify v-validate="'required|email'"
. vee-validate will detect the input type and the required attribute and include those rules for you automatically, so you would only need to add v-validate
on the input.
<input
name="email"
type="email"
required
v-validate
>
Disabling Inferred Rules
You can disable this feature by setting the useConstraintAttrs
to false
when configuring vee-validate.
Vue.use(VeeValidate, {
useConstraintAttrs: false
});
Demo
Inferred Rules Reference
This is a table of HTML attributes that is inferred as rules.
Attribute | value | Rule |
---|---|---|
type | "email" | email |
type | "number" | decimal |
type | "date" | date_format:YYYY-MM-DD |
type | "datetime-local" | date_format: YYYY-MM-DDThh:mm |
type | "time" | date_format:hh:mm or date_format:hh:mm:ss depending on the step value |
type | "week" | date_format:YYYY-Www |
type | "month | date_format:YYYY-MM |
min | val | min_value:val |
max | val | max_value:val |
pattern | rgx | regex: rgx |
required | none | required |
maxlength | "val" | max: val |
minlength | "val" | min: val |
TIP
This feature does not work on custom components, only HTML5 inputs can take advantage from this feature.