是否有一个用于node.js的好的验证框架,该框架可以验证以下变量:
我最近发现了chriso的node- validator。
例
var check = require('validator').check, sanitize = require('validator').sanitize //Validate check('test@email.com').len(6, 64).isEmail(); //Methods are chainable check('abc').isInt(); //Throws 'Invalid integer' check('abc', 'Please enter a number').isInt(); //Throws 'Please enter a number' check('abcdefghijklmnopzrtsuvqxyz').is(/^[a-z]+$/); //Sanitize / Filter var int = sanitize('0123').toInt(); //123 var bool = sanitize('true').toBoolean(); //true var str = sanitize(' \s\t\r hello \n').trim(); //'hello' var str = sanitize('aaaaaaaaab').ltrim('a'); //'b' var str = sanitize(large_input_str).xss(); var str = sanitize('<a>').entityDecode(); //'<a>'