Closed aflext closed 8 years ago
Hi! 😺
Cannot use the all validators with array syntax. You need to object syntax in multiple validators.
...
<input type="text" v-validate:field1="{ required: true, minlength: { rule: 10 }, maxlength: { rule: 29 } ... }">
...
see the validator syntax
@kazupon Thanks a lot for reply! You are saying that i could use a dummy rule for custom validator like numeric
with maxlength
when specify the field name to field params attribute
like below ?
new Vue({
el: '#app',
validators: {
// `numeric` and `url` custom validator is local registration
numeric: {
message: 'xxx',
check: function (val) {
return (/^[-+]?[0-9]+$/).test(val);
}
},
url: {
message: 'xxx',
check: function (val) {
return (/^(http\:\/\/|https\:\/\/)(.{4,})$/).test(val);
}
}
},
data: {
fields: [{
id: 'username',
label: 'username',
name: 'username',
placeholder: 'input your username',
validate: { required: true, maxlength: 16 , numeric: true, email: true}
}, {
id: 'message',
label: 'message',
name: 'message',
placeholder: 'input your message',
validate: { required: true, minlength: 8 , numeric: true, email: true}
}]
}
})
If you don't use the second argment of check
, you should use the dummy rule.
In the above your example, you can use the dummy rule due to check
function of numericand
url` are defined the static rule.
I have a field need to be validated for
required/minleng/maxleng
and a custom validatornumeric
, but i have already used thefield params attribute
, so how to use a customnumeric
at the same time on the same field. Note that the custom validatornumeric
dose not need any parameter.