joi.string() fails on empty string

Created on 1 Oct 2014  路  2Comments  路  Source: sideway/joi

I have a property "email" that is defined like this:
email: joi.string().description('E-mail')

(so not required())

However, this object doesn't validate:

{
"email": ""
}

Is this gives the message "email is not allowed to be empty"

What can I do to have a property that's a string but that can also be an empty string? If I use joi.any() it passes, but of course I only want strings or empty strings. I also don't want to remove the empty properties before validating, because I effectively want to store an empty value in the database.

support

Most helpful comment

Did you try joi.string().allow('')?

All 2 comments

Did you try joi.string().allow('')?

My bad, I didn't see it under string but indeed it works! Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dreamystify picture Dreamystify  路  4Comments

jamesdixon picture jamesdixon  路  4Comments

REBELinBLUE picture REBELinBLUE  路  3Comments

normancarcamo picture normancarcamo  路  3Comments

chrisegner picture chrisegner  路  4Comments