一个简单数据校验JS库:validate.js
jopen
9年前
一个简单数据校验JS库:validate.js</span></strong>
Install
ValidateJS is available on npm:
npm install valid.js --save
or bower:
bower install valid.js
Usage
With ES6/import
import {validate, string, util} from 'valid.js' let isvalid = validate(string.maxLength(15), util.isRequired) let result = isvalid('Test ValidateJS') // result => true
With require
var validatejs = require('valid.js') var validate = validatejs.validate, string = validatejs.string, util = validatejs.util var isvalid = validate(string.maxLength(15), util.isRequired) var result = isvalid('Test ValidateJS') // result => true
With Browser
<script src="./bower_components/valid.js/dist/validate.js"></script>
var validate = validate.validate var string = validate.string var util = validate.util var isvalid = validate(string.maxLength(15), util.isRequired) var result = isvalid('Test ValidateJS') // result => true
OR
var validate = window.validate.validate var string = window.validate.string var util = window.validate.util var isvalid = validate(string.maxLength(15), util.isRequired) var result = isvalid('Test ValidateJS') // result => true