I'm using Joi validation in React with this schema:
...
intro_video_link:
Joi.string()
.uri()
.label("Intro Video"),
...
The intro_video_link is also required. I want Joi to validate field for uri if it is filled, but also allow it to be empty. There is no .required() called.
How?
Thank you
You probably want to combine .allow() with .required():
intro_video_link: Joi.string().uri().label("Intro Video").required().allow('')
This way, the following objects will pass the validation:
{
intro_video_link: ''
}
{
intro_video_link: 'https://github.com'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With