Joi: allowing string, empty string or null

Created on 3 Aug 2016  路  4Comments  路  Source: sideway/joi

Hi,

First off, love this library. Absolutely fantastic work!

Quick question: is there an easier way to allow a value to be a string, empty string or null then the following?

schema = Joi.string().allow('').allow(null)

Appreciate the help!

Best,
James

support

Most helpful comment

Joi.string().allow('', null). I don't think you can make it shorter than that.

All 4 comments

A single allow, but other than that no. Why ?

What exactly do you mean by a "single allow?"

As for why, I'm using Ember on the frontend and Ember Data sends all fields regardless if they're filled in or not. That said, for text fields, I may receive a null value or an empty string if the user happens to delete text that was already in the field. I was just looking for simpler, less verbose way of defining the validation.

Joi.string().allow('', null). I don't think you can make it shorter than that.

Ah, didn't realize it could take multiple params. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skiwi2 picture skiwi2  路  19Comments

hueniverse picture hueniverse  路  26Comments

srkimir picture srkimir  路  17Comments

igorescobar picture igorescobar  路  18Comments

rooftopsparrow picture rooftopsparrow  路  21Comments