我的 API 中有一個輸入,我需要驗證它并查看它是否是我想要的兩個字串之一。有沒有辦法用 Joi.js 驗證字串
type DummyValidatorInput = {
firstInput: string;
secondInput: string;
}
export const DummyValidator = (
input: DummyValidatorInput,
): Joi.ValidationResult => {
return Joi.object({
firstInput: Joi.string().min(5).max(64).required(),
secondInput: Joi.string().required()
}).validate(input);
};
我想驗證secondInput是customerTypeOne字串還是customerTypeTwo字串,Joi 是否可以這樣做?任何想法或建議表示贊賞:)
uj5u.com熱心網友回復:
你試過使用any.valid嗎?
secondInput: Joi.string().valid('customerTypeOne', 'customerTypeTwo').required()
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/326946.html
上一篇:文本框和標簽不匹配問題!VB6
