-
Notifications
You must be signed in to change notification settings - Fork 8
Rules
Oscar edited this page Nov 12, 2018
·
3 revisions
All rules but required
are reolved as correct if value is undefined
or null
so don't forget to add the required
rule if they are.
If values come from an input they will be string unless you use the modifier v-model.number
which will cast the value to number.
To define the rules of each data path you must include vdRules
in your component, imitating the data path.
The array elements will take rules defined for the array.
Example:
data: () => ({
owner: {
name: undefined,
email: undefined
},
phones: [
'123456789',
'987654321'
],
addressBook: [{
name: 'name 1',
addres: 'addres 1'
}, {
name: 'name 1',
addres: 'addres 1'
}]
}),
vdRules: {
owner: {
name: { required: true, minlen: 4 },
email: { type: 'email' }
},
phones: { required: true, minlen: 9 },
addressBook: {
name: { required: true },
addres: { required: true, minlen: 10 }
}
}
Rule | Description |
---|---|
type | Check the type of value, supporting boolean, number, integer, float, string, url, email and date |
required | Check if value is empty |
regexp | Check the value against regular expression |
min | Check if value is greater than the number specified |
max | Check if value is less than the number specified |
minlen | Check if value lengh is greater than the number specified |
maxlen | Check if value lengh is less than the number specified |
length | Check if value lengh is exactly the number specified |
equals | Check if value equals another value |
is | Check if value is a given one |
isnot | Check if value is not a given one |
isin | Check if value is in a string or one element of an array |
If a rule depends on other factors, you can pass a function to the rule that will be run to determine the rule application.