A library for data validation.
ValidateJS is available on npm:
npm install valid.js --save
or bower:
bower install valid.js
import {validate, string, util, isValid} from 'valid.js'
let testIsValid = validate(string.maxLength(15), util.isRequired)
let result = testIsValid('Test ValidateJS')
// result => true
// or using the 'isValid' shorthand method
let result = isValid('Test ValidateJS', [string.maxLength(15), util.isRequired])
// result => true
var validatejs = require('valid.js')
var validate = validatejs.validate,
isValid = validatejs.isValid,
string = validatejs.string,
util = validatejs.util
var testIsValid = validate(string.maxLength(15), util.isRequired)
var result = testIsValid('Test ValidateJS')
// result => true
// or using the 'isValid' shorthand method
var result = isValid('Test ValidateJS', [string.maxLength(15), util.isRequired])
// result => true
<script src="./bower_components/valid.js/dist/validate.js"></script>
var validate = validate.validate
var string = validate.string
var util = validate.util
var testIsValid = validate(string.maxLength(15), util.isRequired)
var result = testIsValid('Test ValidateJS')
// result => true
OR
var validate = window.validate.validate
var string = window.validate.string
var util = window.validate.util
var testIsValid = validate(string.maxLength(15), util.isRequired)
var result = testIsValid('Test ValidateJS')
// result => true
OR
var isValid = window.validate.isValid
var string = window.validate.string
var util = window.validate.util
var result = isValid('Test ValidateJS', [string.maxLength(15), util.isRequired])
// result => true
Also available for AMD
- String
- isString
- minLength(min)
- maxLength(max)
- length(min, max)
- regex(reg)
- Number
- isNumber
- minNumber
- maxNumber
- between
- Date
- isDate
- minDate(min)
- maxDate(max)
- between(min, max)
- Bool
- isTrue
- isFalse
- Util
- isRequired
- isEmail
- isCep
- isUrl
- isHexColor
- isCpf
- isCnpj
- Credit Card
- isVisa
- isElo
- isHipercard
- isMasterCard
- isDiners
- isAmex
- isCreditCard
Send us a Pull Request! Here is how:
- Fork it!
- Create your feature branch: git checkout -b my-new-feature
- Stage your changes: git add .
- Commit your changes: git commit -m 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request
The MIT License (MIT)
Copyright (c) 2015 Daniel Leite de Oliveira
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.