Reputation: 87
I am to pass a vat value. The validation should allow saving it in the db if it is empty or passes the given regex of a certain country.
.when('country_code', {
is: 'AT',
then: Joi.alternatives([
Joi.string().allow(''),
Joi.string().regex(/(AT)?U[0-9]{8}/)
])
})
This what I have achieved till now but it isn't working.
Upvotes: 1
Views: 875
Reputation: 325
This is what you are looking for:
Joi.string().regex(/(AT)?U[0-9]{8}$/).allow('')
Upvotes: 2