egg-async-validate
Validate plugin for egg, compatible egg-validate method.
see async-validate for more information such as custom rule.
Install
$ npm i egg-ivalidate --save
Usage
exports.validate = {
enable: true,
package: 'egg-ivalidate',
};
Configuration
exports.validate = {
messages: {},
};
see async-validator#messages for more detail.
Example
exports.index = async ctx => {
await ctx.validate({
data: { type: 'object', required: true },
}, {
data: '1',
});
try {
await ctx.validate({ data: { type: 'object', required: true } });
} catch (err) {
const errors = err.errors;
}
};
rules see async-validator#rules for more detail.
!!important: method
,date
,hex
in type
does not apply to server - side form validation