Question: Nodejs - Joi Check if string is in a given list

Question

Nodejs - Joi Check if string is in a given list

Answers 1
Added at 2016-12-31 13:12
Tags
Question

I'm using Joi package for server side Validation.
I want to check if a given string is in a given list or if it is not in a given list.(define black list or white list for values)
sth like an "in" or "notIn" function.how can I do that?

var schema = Joi.object().keys({
    firstname: Joi.string().in(['a','b']),
    lastname : Joi.string().notIn(['c','d']),
});
Answers to

Nodejs - Joi Check if string is in a given list

nr: #1 dodano: 2016-12-31 14:12

How about:

var schema = Joi.object().keys({
    firstname: Joi.string().valid(['a','b']),
    lastname : Joi.string().invalid(['c','d']),
});

There are also aliases: .allow and .only

and .disallow and .not

Source Show
◀ Wstecz