[英]How to get customised message for Joi label
What currently I have is this:我目前拥有的是:
example: Joi.boolean()
.required()
.invalid(false)
.label('Disclaimer Checkbox'),
and the output which I am getting is "Disclaimer checkbox contains invalid value".我得到的 output 是“免责声明复选框包含无效值”。
What I need is label which contain only message which I wrote not "contains invalid value"我需要的是 label,它只包含我写的不是“包含无效值”的消息
a: Joi.string()
.min(2)
.max(10)
.required()
.messages({
'string.base': `"a" should be a type of 'text'`,
'string.empty': `"a" cannot be an empty field`,
'string.min': `"a" should have a minimum length of {#limit}`,
'any.required': `"a" is a required field`
})
});
When defining joi validations, you need to assert messages along with their validation string to define an error message against it, like the example below.在定义 joi 验证时,您需要断言消息及其验证字符串以针对它定义错误消息,如下例所示。
bodyValidation: Joi.integer()
.min(1997)
.max(2022)
.regex(/[0-9],{4}/)
.required()
.messages({
'integer.base': `Entered data should be an integer`,
'integer.regex': `Entered field is not an year`,
'integer.min': `Entered Year is less than 1997`,
'any.required': `Entry is required`
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.