is.valid
Validation library for node.js inspired from the old famous codeigniter validation library.
How to use
Install from npm
npm install is.valid
Instantiate a new is.valid object
var IsValid = require('is.valid');
var data = {
name: 'foo bar',
email: 'foo@bar.com'
}
var isValid = new IsValid(data);
Add validation rules
isValid.addRule('name', 'Name', 'required|minLength[10]');
Run validation rules
isValid.run(function(err, data){
});
Validation functions
required: validates that a value exists
minLength[l]: validates that a value length is at minimum equal to l
maxLength[l]: validates that a value length is at maximum equal to l
exactLength[l]: validates that a value length is exactly l
greaterThan[l]: validate that a value is greater than l
lessThan[l]: validates that a value is less than l
alpha: validates that a value contains only alphabet letters [A-Za-z]
alphaNumeric: validates that a value contains only alphabet letters or numbers [A-Za-z0-9]
alphaNumericDash: validates that a value contains only alphabet letters, numbers or dash [A-Za-z0-9-]
numeric: validates that a value is numeric [0-9]
integer: validates that a value is an integer
decimal: validates that a value is a decimal number
natural: validates that a value is a natural number >= 0
naturalNoZero: validates that a value is a natural number and greater than zero
email: validates that a value looks like an email
regex[s]: validates that a value matches the given regular expressions s
matches[f]: validates that a value matches a value of another field f
list: validates that a value is a list
minListLength[l]: validates that a list has a minimum length l
maxListLength[l]: validates that a list doesn't exceed a maximum length l
date: validates that a value is an actual date
beforeDate[l]: validates that a date is earlier than another date l
afterDate[l]: validates that a date is later than another date l
boolean: validates that a value is either true or false
sanitize: sanitize a value against any possible xss attacks