vuelidation icon indicating copy to clipboard operation
vuelidation copied to clipboard

Custom rules

Open glutaminefree opened this issue 6 years ago • 2 comments
trafficstars

Hi! Great library! What about adding custom rules? Or regex rule at least? :)

glutaminefree avatar Nov 18 '19 12:11 glutaminefree

@cj maybe you can help with this one?

lukasborawski avatar Jun 16 '20 10:06 lukasborawski

@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

jac0b95 avatar Jun 30 '20 02:06 jac0b95