Reputation: 47871
Why is this regex should match but it's failing?
error
child "color" fails because ["color" with value "#333acf " fails to match the required pattern: /^#[A-Fa-f0-9]{6}$/]
validate: {
payload:{
avatar: joi.object().keys({
color: joi.string().regex(/^#[A-Fa-f0-9]{6}$/),
icon: joi.string().min(2)
})
}
}
payload
{
"avatar": {color:"#333acf ",icon:"b1"}
}
Upvotes: 3
Views: 4000
Reputation: 4249
Your color string has an extra space at the end. Should be
{
"avatar": {color:"#333acf",icon:"b1"}
}
or your regex needs to allow strings longer than 6 characters by removing the end of string anchor.
/^#[A-Fa-f0-9]{6}/
Upvotes: 4