Universal Validator
Universal Validator.
Install
via spm@3.x:
$ spm install univ
via npm:
$ npm install univ
Usage
var Validator = ; var rules = "username": type: "email" required: true // @param {String} value. // @param {Function} certifiedCallback, optional. { $; //!return undefined; } "password": type: "password" required: true minlength: 6 maxlength: 30 "re-password": type: "password" required: true minlength: 6 maxlength: 30 { return value === thisdata"password"; } ; var validator = rules;validator;
API
Validator(ruler)
constructor, new a validator by rulers.
// rule name. "name": type: required: Boolean max: Number min: Number maxlength: Number minlength: Number pattern: RegExp multiple: Boolean step: Number accept: Array<String> custom: Function "other-name": // ... // ...
Univ.rule(name, rule)
Set or get a custom rule.
validator;
univ.validate(data)
data:
univ;
Events
valid
单个数据项通过校验,数据合法有效。
validator;
invalid
单个数据项未通过校验,数据无效、不合法。
validator;
complete
所有数据校验完成。数据是否全部通过校验,则视事件处理函数的对应参数。
// @param {Boolean} certified.validator;
error
校验过程中出现异常,则抛出 error
事件。
// @param {Error} errorvalidator;