I'm trying to validate an input field with vuelidate. I need it to return valid if either of the following regular expressions is true.
const val1 = helpers.regex('val1', /^\D*7(\D*\d){12}\D*$/)
const val2 = helpers.regex('val2', /^\D*1(\D*\d){11}\D*$/)
const checkvals = () => {
if(val1 || val2) {
return true
} else{
return false
}
}
Validation
numbercheck: {
required,
checkvals
},
How do I get this to work?
Solution
import { or, helpers, required } from 'vuelidate/lib/validators'
const val1 = helpers.regex('val1', /^\D*7(\D*\d){12}\D*$/)
const val2 = helpers.regex('val2', /^\D*1(\D*\d)11}\D*$/)
checkvals: {
numbercheck,
valid: or(val1, val2)
},
Solution 2
const numbercheck = helpers.regex("mob", /^\D*(?:7(?:\D*\d){12}|1(?:\D*\d)11})\D*$/);
Validation
checkvals: {
required,
numeric,
numbercheck,
},