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

REBELinBLUE picture REBELinBLUE  路  3Comments

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

kevbook picture kevbook  路  4Comments

kailashyogeshwar85 picture kailashyogeshwar85  路  4Comments

PaunPrashant picture PaunPrashant  路  3Comments