Skip to content

Instantly share code, notes, and snippets.

@seldo
Created May 12, 2014 23:52
Show Gist options
  • Save seldo/0d42f579bca7fdf6e4f9 to your computer and use it in GitHub Desktop.
Save seldo/0d42f579bca7fdf6e4f9 to your computer and use it in GitHub Desktop.
var Joi = require('joi');
var schema = Joi.object().keys({
username: Joi.string().alphanum().min(3).max(30).required(),
password: Joi.string().regex(/[a-zA-Z0-9]{3,30}/),
access_token: [Joi.string(), Joi.number()],
birthyear: Joi.number().integer().min(1900).max(2013),
email: Joi.string().email()
}).with('username', 'birthyear').without('password', 'access_token');
Joi.validate({ username: 'abc', birthyear: 1994 }, schema, function (err, value) { }); // err === null -> valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment