It seems pretty straight forward to validate user's input in Node.js RESTapi with Joi
.
But the problem is that my app is not written in English.
That means I need to send a custom written messages to the frontend user.
I have googled for this and only found issues.
Maybe could someone give a solution for this?
This is the code I am using to validate with the Joi
system:
var schema = Joi.object().keys({
firstName: Joi.string().min(5).max(10).required(),
lastName: Joi.string().min(5).max(10).required()
..
});
Joi.validate(req.body, schema, function(err, value) {
if (err) {
return catched(err.details);
}
});
function catched(reject) {
res.json({
validData: false,
errors: reject
});
}
Plus, is there a way to use Joi
in client side?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…