如何允许空字符串或由 JOI 中的正则表达式验证的字符串?

How to allow empty or a string validated by a regex in JOI?

我要传递增值税价值。如果它为空或通过特定国家/地区的给定正则表达式,则验证应允许将其保存在数据库中。

.when('country_code', {
                is: 'AT',
                then: Joi.alternatives([
                    Joi.string().allow(''),
                    Joi.string().regex(/(AT)?U[0-9]{8}/)
                ])
            })

这是我到目前为止所取得的成就,但它没有用。

这就是您要查找的内容: Joi.string().regex(/(AT)?U[0-9]{8}$/).allow('')