微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

forgJs

编程之家收集整理的这个编程导航主要介绍了forgJs编程之家,现在分享给大家,也给大家做个参考。

forgJs 介绍

通过运行来通过npm安装它 

npm i @cesium133/forgjs

 示例:

onst { Validator,Rule } = require('@cesium133/forgjs');

const emailRule = new Rule({

type: 'email',

user: user => user === 'dedede',

domain: domain => ['outlook','gmail','yahoo'].indexOf(domain) !== -1,

},null);

const passwordRule = new Rule({

type: 'password',

minLength: 8,

uppercase: 1,

numbers: 1,

matchesOneOf: ['@','_','-','.','!'],null);

const vComplexe = new Validator({

age: new Rule({ type: 'int',min: 18,max: 99 }),

dateOfBirth: new Rule({ type: 'date' }),

array: new Rule({ type: 'array',of: new Rule({ type: 'string' }) }),

email: emailRule

pasword: passwordRule

});

vComplexe.test({

age: 26,

dateOfBirth: new Date(1995,10,3),

array: ['1'],

email: '[email protected];',

password: 'ad1_A@@Axs',

}); /// returns true

错误处理 

这样做可以获得自定义消息错误

const vComplexe = new Validator({

age: new Rule({

type: 'int',max: 99,'age must be integer and between 18 and 99'),

dateOfBirth: new Rule({ type: 'date' },'date must be a date'),

});

vComplexe.getErrors({

age: 16,

dateOfBirth: 123,

}); // ['age must be integer and between 18 and 99','date must be a date']

GitHub:https://github.com/oussamahamdaoui/forgJs

网站描述:一个轻量级js表单验证器

forgJs

官方网站:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。