vuelidation
vuelidation copied to clipboard
Custom rules
trafficstars
Hi! Great library! What about adding custom rules? Or regex rule at least? :)
@cj maybe you can help with this one?
@glutaminefree
If You want to extend Vuelidation by custom rules just pass option object
Vue.use(Vuelidation, {
methods: {
customValidationRule(value, args) {
console.log(value, args) // log to console to see how it looks
const valid = false
const msg = 'Some validation message'
return [valid, msg]
},
},
})
and use it like this
vuelidation: {
data: {
first_name: {
required: true,
customValidationRule: true,
},
},
},
Place where the magic happens:
https://github.com/cj/vuelidation/blob/63c188b02c6e95fc48756901ee659e2cd0ae7951/src/index.js#L161-L166