is.valid v0.5.3
is.valid
Validation library for node.js inspired from the old famous codeigniter validation library.
How to use
Install from npm
npm install is.validInstantiate a new is.valid object
var IsValid = require('is.valid');
/** construct a new is.valid object passing the data array to validate
  * date array should contain a set of objects formatted as following
  * {fieldName: value}
 */
var data = {
	name: 'foo bar',
	email: 'foo@bar.com'
}
var isValid = new IsValid(data);Add validation rules
/**
  * to add validation rules use addRule function
  * addRule accepts 3 arguments
  * field Name as in data object
  * friendly Name for error messages
  * rules separated by |
  * rule is specified by a name and optionaly options
  * like for minLength you should also submit what is the minimum length
  * using the brackets way [10]
 **/
isValid.addRule('name', 'Name', 'required|minLength[10]');Run validation rules
/**
  * run function go through all validation rules you specified for all fields
  * it accepts a callback function
  * where err is an array contains all error messages formatted like
  * {fieldName: errorMessage }
  * or null if no errors have been found
  * and data is the data object
 **/
isValid.run(function(err, data){
});Validation functions
required: validates that a value exists
minLengthl: validates that a value length is at minimum equal to l
maxLengthl: validates that a value length is at maximum equal to l
exactLengthl: validates that a value length is exactly l
greaterThanl: validate that a value is greater than l
lessThanl: 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
regexs: validates that a value matches the given regular expressions s
matchesf: validates that a value matches a value of another field f
list: validates that a value is a list
minListLengthl: validates that a list has a minimum length l
maxListLengthl: validates that a list doesn't exceed a maximum length l
date: validates that a value is an actual date
beforeDatel: validates that a date is earlier than another date l
afterDatel: 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
