Guest User

Untitled

a guest
Feb 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. const Joi = require('joi');
  2.  
  3. const schema = Joi.object().keys({
  4. username: Joi.string().alphanum().min(3).max(30).required(),
  5. password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/),
  6. access_token: [Joi.string(), Joi.number()],
  7. birthyear: Joi.number().integer().min(1900).max(2013),
  8. email: Joi.string().email()
  9. }).with('username', 'birthyear').without('password', 'access_token');
  10.  
  11. // Return result.
  12. const result = Joi.validate({ username: 'abc', birthyear: 1994 }, schema);
  13. // result.error === null -> valid
  14.  
  15. // You can also pass a callback which will be called synchronously with the validation result.
  16. Joi.validate({ username: 'abc', birthyear: 1994 }, schema, function (err, value) { }); // err === null -> valid
Add Comment
Please, Sign In to add comment