Hi guys i want to make a mutiple regex validation with joi/hapi but i don't understand how to do it i already multiple try but no one works, I want the password minimun have 1 capital letter, 1 minus letter, 1 number and 1 special character here ones of my try:
const passwordValidation = (data) => {
const schema = Joi.object({
password: Joi.string()
.pattern(new RegExp('^[a-z]{1,}$'))
.pattern(new RegExp('^[A- Z]{1,}$'))
.pattern(new RegExp('^[0 - 9]{1,}'))
.pattern(new RegExp('^[!@#$%&*]{1,}'))
.min(8)
.required()
});
return schema.validate(data);
};
and
const passwordValidation = (data) => {
const schema = Joi.object({
password: Joi.string()
.regex('^[a-z]{1,}$')
.regex('^[A- Z]{1,}$')
.regex('^[0 - 9]{1,}')
.regex('^[!@#$%&*]{1,}')
.min(8)
.required()
});
return schema.validate(data);
};
how i can do it?
regex()
requires the object to be a RegExp object.
And fixes in regex
https://javascript.info/regexp-anchors
Working Demo