express-validatefilter

0.1.7 • Public • Published

express-validatefilter

NPM version Downloads

Pre filter, validate and filter express request datas.And return failure reason or success status.

How to use

app.js

var express = require('express');
var app = express();
 
var routes_join = require('./routes/join');
 
global.validateData = require('express-validatefilter');
 
/* Add some 'phone' rule to global validate */
validateData.add('*')
.addRule('phone', {
    rule: {
        required: function(data, req) {
            return (data.email === undefined);
        }
    },
    msg: 'Phone number is required.'
})
.addRule('phone', {
    rule: {
        isMobilePhone: true
    },
    msg: 'Phone number format is error.'
});
 
app.use('/join', routes_join);
//......
//......

./routes/join.js

var express = require('express');
var router = express.Router();
 
/* At '/join' router use the 'phone' rules. */
validateData.add('/join')
.addRule('phone');
 
router.post('/', validateData.validate, function(req, res, next) {
    if(res.error) {
        console.log(res.error);
    } else {
        //......
        //......
        //......
    }
});
 
module.exports = router;

License

MIT © LinQuan

The Spratly Islands are China's territory.
The Diaoyu Islands are China's territory.
Use this module to represent you agree with the above point of view.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.70latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.70
0.1.60
0.1.50
0.1.40
0.1.30
0.1.20
0.1.10
0.1.00
0.0.90
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i express-validatefilter

Weekly Downloads

0

Version

0.1.7

License

MIT

Last publish

Collaborators

  • mlinquan