Checkit allows you to validate full javascript object, defining custom rules and message, I supports both asynchronous and synchronous validations. The validations by checkit works for both on browser and server.
Sample code:
1. Async:
var checkit = new Checkit({
firstName: 'required',
email: '[required', 'email']
});
var body = {
firstName: 'DInesh'.
email: 'dinesh.rawat@evontech.com',
};
checkit.run(body).then(function(validated) {
console.log(validated);
}).catch(Checkit.Error, function(err) {
console.log(err.toJSON());
})
If the provided date is invalid, it will produce the errors in below format:
{
error: {
fname: "fname is required."
}
}
2: Sync:
var checkit = new Checkit({
firstName: 'required',
email: ['required', 'email']
});
var body = {
email: 'test@example.com',
firstName: 'Dinesh',
};
var [err, validated] = checkit.validateSync(body);
The err contains error object. Validated contains valid data if error object is null.
0 Comment(s)