admin管理员组文章数量:1400007
I want to validate object using Joi which inovle use of Joi.ref() with multiplication operation.
var object = {
a: 5,
b: 6
}
// this is wrong as Joi.ref('a')*2 is now allowed in max()
var schema = Joi.object({
a: Joi.number().integer(),
b: Joi.number().integer().min(1).max(Joi.ref('a')*2)
})
Joi.ref('a')*2
is not allowed. So how can I validate object such that b<=2*a
?
I want to validate object using Joi which inovle use of Joi.ref() with multiplication operation.
var object = {
a: 5,
b: 6
}
// this is wrong as Joi.ref('a')*2 is now allowed in max()
var schema = Joi.object({
a: Joi.number().integer(),
b: Joi.number().integer().min(1).max(Joi.ref('a')*2)
})
Joi.ref('a')*2
is not allowed. So how can I validate object such that b<=2*a
?
1 Answer
Reset to default 8Using adjust
option
var schema = Joi.object({
a: Joi.number().integer(),
b: Joi.number().integer().min(1).max(Joi.ref('a', {
adjust: (value) => value * 2
}))
})
stackblitz
本文标签: javascriptHow to use maths operation with Joiref() for validating object using JoiStack Overflow
版权声明:本文标题:javascript - How to use maths operation with Joi.ref() for validating object using Joi? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744212521a2595487.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论