Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuetify validation using multiple rules

Is it possible to assign multiple rules to validate input? For example I have two rules:

alphaRule: [
      v => /[a-zA-Z]+$/.test(v) || 'Field must only contain letters'
    ],
requiredRule: [
               v => !!v || "required field"
            ]

And I have number of controls. Some of them need only requiredRules, some - only alphaRule, but some - combination of alphaRule and requiredRule.

Can I combine it together?

something like

:rules = "alphaRule, requiredRule"
like image 829
Andrey Avatar asked Oct 31 '25 09:10

Andrey


2 Answers

If you want to leave both variables, you can just work with them like with JS arrays.

:rules = "alphaRule.concat(requiredRule)"
like image 176
Alexander Shkirkov Avatar answered Nov 02 '25 22:11

Alexander Shkirkov


Just keep adding the rules into the array:

:rules = "[alphaRule, requiredRule].flat()"
like image 23
Mayker Miyanaga Avatar answered Nov 02 '25 22:11

Mayker Miyanaga