Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Created September 30, 2014 18:37
Show Gist options
  • Select an option

  • Save alanhoff/4b963a1b2d11615c3e11 to your computer and use it in GitHub Desktop.

Select an option

Save alanhoff/4b963a1b2d11615c3e11 to your computer and use it in GitHub Desktop.
var user = require('./userSchema');
user.validate({password: 'alan', email: 'huehue@br.br'}, function(err, data){
if(err)
throw err;
//gravar o data no banco de dados
db.insert(data);
});
var Joi = require('joi');
var schema = Joi.object().keys({
attributes: Joi.object(),
password: Joi.string().regex(/[a-zA-Z0-9]{3,30}/),
email: Joi.string().email()
}).with('email', 'attributes').without('password');
module.exports = {
validate: function(data, callback){
Joi.validate(data, schema, callback);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment