vdjsJavaScript 数据验证库
vdjs
一个简单实用的数据验证对象,适用于浏览器与node环境。
安装
npm install -S vdjs
var validator = require('./dist/validator.js') // 待验证数据 var data = { name: 'validator', nickname: 'validator.js', password: '123456', confirm_password: '1234561' } // 验证数据 var valid = validator.validate(data, { name: [ {required: true, msg: 'name字段不能为空'}, {type: String, msg: 'name字段必须是字符串'}, {length: [3, 20], msg: 'name字段保持3~20字符'}, ], nickname: {length: [3, 20], msg: 'nickname字段保持3~20字符'}, password: {required: true, not: '123456', min: 6, msg: 'password验证不通过'}, confirm_password: {eq: data.password, msg: '两次输入密码不一致'} }) console.log(valid.fails(), valid.valider(), valid.has('name'), valid.all(true))
评论