admin管理员组文章数量:1296910
A classical example is:
schema = Joi.object().keys({
my_string: Joi.string().valid("myString").required()
});
This validate that object have field my_string
which must have a myString
as value.
How check that key my_string
is not equal to notAllowedString
?
A classical example is:
schema = Joi.object().keys({
my_string: Joi.string().valid("myString").required()
});
This validate that object have field my_string
which must have a myString
as value.
How check that key my_string
is not equal to notAllowedString
?
1 Answer
Reset to default 12you can use invalid to blacklist a value (link for ref)
schema = Joi.object().keys({
my_string: Joi.string().invalid("notAllowedString").required()
});
Here's a full example of how you would use it:
const Joi = require('joi');
const schema = Joi.object({
someIntA: Joi.number().integer().min(0).required(),
someIntB: Joi.number()
.integer()
.min(0)
.invalid(Joi.ref('someIntA'))
.required(),
someStringA: Joi.string().alphanum().min(3).max(30).required(),
someStringB: Joi.string()
.alphanum()
.min(3)
.max(30)
.invalid(Joi.ref('someStringA'))
.required(),
});
本文标签: javascriptHow to validate that a string is not equal to another (blacklist) with JoiStack Overflow
版权声明:本文标题:javascript - How to validate that a string is not equal to another (blacklist) with Joi? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741605457a2387950.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论