For my registration page I created custom validator to check if inputed registration password matches specific criteria's. Like minLength 12 chars, must contains at least one digit etc.
The problem start here. Because by some means my custom validator do not get value when its fired. In console it shows undefined.
Just in case I used mustache code to check if inputted data is written to variable. Yes it does.
The validator code
This solution was found here click
import { minLength, helpers } from '@vuelidate/validators';//all okey with import
const passwordValidators = {
minLength: minLength(12),
containsUppercase: helpers.withMessage(
() => 'Password does not contain any Uppercase characters (A-Z)',
function(value: string): boolean {
console.log(value);//value is undefined
return /[A-Z]/.test(value);
}
),
containsLowercase: helpers.withMessage(
() => 'Password does not contain any lowercase characters (a-z)',
function(value: string): boolean {
console.log(value);//value is undefined
return /[a-z]/.test(value);
}
),
containsNumber: helpers.withMessage(
() => 'Password does not contain any digit characters (0-9)',
function(value: string): boolean {
console.log(value);//value is undefined
return /[0-9]/.test(value);
}
)
}
export default passwordValidators
How it is used inside vue,js component
//somewhere up
import passwordValidators from '@/validators/password-requirements';
import { required, email, sameAs } from '@vuelidate/validators';
//inside defineComponent
validations() {
return {
email: { required, email },
password: {
required,
passwordValidators
},
firstName: { required },
lastName: { required },
confirmPassword: { required, sameAsPassword: sameAs(this.password) }
}
},
The version of the lib are:
- "@vuelidate/core": "^2.0.0-alpha.34",
- "@vuelidate/validators": "^2.0.0-alpha.26",