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
// {app_root}/config/plugin.jsexportsvalidate = enable: true package: 'egg-ivalidate';
Configuration
// {app_root}/config/config.default.jsexportsvalidate = messages: {};
see async-validator#messages for more detail.
Example
// {app_root}/app/controller/home.jsexportsindex = async { // will throw if invalid. await ctx; // if you want to get errors info, // use try { ... } catch (err) { ... } to get // example try await ctx; // validate target, default to `this.request.body` catch err const errors = errerrors; };
rules see async-validator#rules for more detail.
!!important:
method
,date
,hex
intype
does not apply to server - side form validation