Can someone assist me with validating an input field using vuelidate? I am looking to return a valid result if either of the two regular expressions provided below 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
},
Any suggestions on how I can make this work?
Possible 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)
},
Alternative Solution
const numbercheck = helpers.regex("mob", /^\D*(?:7(?:\D*\d){12}|1(?:\D*\d){11})\D*$/);
Validation
checkvals: {
required,
numeric,
numbercheck,
},