[英]How to validate that a string is not equal to another (blacklist) with Joi?
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. 这验证对象具有字段
my_string
,该字段必须具有myString
作为值。
How check that key my_string
is not equal to notAllowedString
? 如何检查键
my_string
不等于notAllowedString
?
you can use invalid to blacklist a value ( link for ref ) 您可以使用无效将值列入黑名单( ref的链接 )
schema = Joi.object().keys({
my_string: Joi.string().invalid("notAllowedString").required()
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.