plain-validator
v0.1.0
Published
Customize validator.
Downloads
2
Readme
Introduction
Customize validator.
Start
npm install -D plain-validator
Example
// rules.js
import Validator from 'plain-validator'
const validator = new Validator()
validator.define('foo', v => v === 'foo')
export default validator
// validate.js
import validator from './rules.js'
validator.validate('foo', 'foo') // -> true
validator.validate('foo', 'bar') // -> false
// or
validator.isFoo('foo') // -> true
Built-in Rules
email
date
phoneNumber
Use
validator.validate('email', '[email protected]') // -> true
// or
validator.isEmail('[email protected]')
Rewrite
validator.define('email', () => {})