[英]multiple regex/pattern validation Joi Hapi
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:嗨,伙计们,我想用 joi/hapi 进行多重正则表达式验证,但我不明白该怎么做我尝试的 1 个特殊字符:
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.regex()
要求 object 是 RegExp object。
And fixes in regex并修复正则表达式
https://javascript.info/regexp-anchors https://javascript.info/regexp-anchors
Working Demo工作演示
https://stackblitz.com/edit/js-7c78r7?file=index.js https://stackblitz.com/edit/js-7c78r7?file=index.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.