validate2

0.0.3 • Public • Published

简单的表单验证

因validate已被占用,故加了个2后缀

validate2

安装

npm install validate2

使用

var validate2 = new Validate2();
 
var body = {
    username: 'cloudcome',
    password: '123123',
    password2: '12312ddd3',
    email: 'cloudcome@163.co--m',
};
 
 
// setting
validate2.set({
    isSkipInvalid: true,
    body: body,
})
// username
.item('username', [{
    type: 'username',
    settings: {
        minLength: 2,
        maxLength: 3,
    },
    msg: '用户名不合法!',
}])
// password
.item('password', [{
    type: 'password',
    settings: {
        minLength: 2,
        maxLength: 3,
    },
    msg: '密码不合法!',
}])
// password2
.item('password2', [{
    type: 'password',
    msg: '确认密码不合法!',
}, {
    type: 'equal',
    name: 'password',
    msg: '确认密码不一致!',
}])
// email
.item('email', [{
    type: 'email',
    msg: '邮箱不合法!',
}])
// listen
.on('end', function (msg) {
    console.log(msg);
})
// run validate
.validate();

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i validate2

      Weekly Downloads

      1

      Version

      0.0.3

      License

      MIT

      Last publish

      Collaborators

      • cloudcome