Joi: Optional string is not allowed to be empty

Created on 14 Oct 2015  路  6Comments  路  Source: sideway/joi

The next string returns error "value" is not allowed to be empty

Joi.validate('', Joi.string().optional())

Is that a normal behaviour? If yes - than how to allow empty?

support

Most helpful comment

check this if you want to allow empty string , by default joi not allow empty string :
Joi.validate('', Joi.string().allow(''))
it will work for you .

All 6 comments

this does not allow a null value. To do that, use any.allow(value). Or both!

check this if you want to allow empty string , by default joi not allow empty string :
Joi.validate('', Joi.string().allow(''))
it will work for you .

It works thanks ali

ask at any time.
You are welcome.

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JbIPS picture JbIPS  路  4Comments

n-sviridenko picture n-sviridenko  路  3Comments

kevbook picture kevbook  路  4Comments

chrisegner picture chrisegner  路  4Comments

a-c-m picture a-c-m  路  3Comments