suppose we have a password field and we want to do some validations of length, specialcharacters, numbers, upper case and lower case etc, only if the field has a value
how can we do that with vuelidate.
here I am import vuelidate
import { required, minLength, maxLength, email, sameAs } from 'vuelidate/lib/validators'
Here the validations
validations: {
editedItem: {
firstname: { required, minLength: minLength(3), maxLength: maxLength(20) },
lastname: { required, minLength: minLength(3), maxLength: maxLength(20) },
email: { required, email },
password: {
required,
minLength: minLength(6),
maxLength: maxLength(15),
oneNumber,
oneUpperCase,
oneLowerCase,
},
repassword: {
sameAsPassword: sameAs('password'),
},
},
}
,
oneNumber, oneUpperCase and oneLowerCase are custom validations:
const oneNumber = (value) => /[0-9]/.test(value)
const oneUpperCase = (value) => /[A-Z]/.test(value)
const oneLowerCase = (value) => /[a-z]/.test(value)
I will forever appreciate any help or advice
isDirty, but it is not exactly what you want because it will show invalid value when user clears the password field.