Is it possible to validate that two object properties of type string
are equal using Joi
?
I found Joi.ref()
but I wonder if there's another way of doing it. Especially as Joi.ref()
doesn't seem to support any.error()
Is it possible to validate that two object properties of type string
are equal using Joi
?
I found Joi.ref()
but I wonder if there's another way of doing it. Especially as Joi.ref()
doesn't seem to support any.error()
Yes, it is possible to check if two properties on a object are the same. And using
Joi.ref()
is the preferred way to do it.If you want to use custom error messages the
Joi.any.messages()
option works the best. TheJoi.any.messages()
lets you overwrite the different error messages that a property is producing.You could also use the
Joi.any.error()
option but that is not that elegant and you would need to switch between the different error codes (likestring.base
,any.required
,any.only
...)Complete Solution using
Joi.any.messages()