![](/img/trans.png)
[英]Validate that two keys of object should have same value using Joi?
[英]How to validate object with two max condition on a value in Joi?
我想使用Joi驗證這個 object 條件:
b
應大於 2。
b
不能大於a
。
b
不能大於600
// valid object
var object = {
a: 5,
b: 3
}
// invalid object because b > a
var object = {
a: 5,
b: 6
}
我很想建立 Joi 模式
var schema = Joi.object({
a: Joi.number().integer(),
b: Joi.number().integer().min(2).max(Joi.ref('a')).max(600)
})
此模式忽略b<=a
條件,因此無效的 object 也被視為有效。 應用所有條件的正確模式應該是什么?
var schema = Joi.object({
a: Joi.number().integer(),
b: Joi.number().integer().min(2).max(Joi.ref('a')).less(601)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.