0.5.1 • Published 11 years ago

laravel-validator-for-js v0.5.1

Weekly downloads
27
License
-
Repository
github
Last release
11 years ago

##validator.js

Setup

Browser usage:
  1. Include validator.js or validator.min.js script onto your page from the distribution folder (dist).
  2. Invoke the Validator constructor function. See below for details on Validator parameters and validation rules.
Node.js Usage:
	npm install laravel-validator-for-js
  • On your node.js script, require the module.
	var ValidationModule = require('laravel-validator-for-js');

	var validation = new ValidationModule.Validator({
		name: 'John',
		age: 45,
		email: 'johndoe.gmail.com'
	}, {
		name: 'required',
		age: 'numeric',
		email: 'required|email'
	});
  • Invoke the Validator constructor function.

Examples

The 1st argument to the constructor is an object that contains the data you want to validate.

The 2nd argument is an object that contains the validation rules.

#####Example 1:

	var data = {
		email: 'johndoe@gmail.com'
	};
	
	var rules = {
		email: 'email'
	};

	var validation = new Validator(data, rules);
	
	validation.passes() // true
	validation.fails() // false
	

To apply validation rules to the input object, use the same object key names for the rules object.

#####Example 2:

	var rules = {
		name: 'required|size:3',
		email: 'required|email'
	};

	var data = {
		name: '',
		email: ''
	};

	var validation = new Validator(data, rules);

	validation.fails(); // true

###Validation Rules

  • required - Checks if the length of the String representation of the value is > 0
	username: 'required'
  • email - Checks for an @ symbol followed by a period
	address: 'email'
  • size - Validate that an attribute is a given length, or, if an attribute is numeric, is a given value
	duration: 'size:2'
  • min - Validate that an attribute is at least a given size.
	payment: 'min:10'
	
  • max - Validate that an attribute is no greater than a given size
	cost: 'max:100'
  • numeric - Validate that an attribute is numeric. The string representation of a number will pass.
	age: 'numeric'

Note: All minimum and maximum checks are inclusive.

###Public Instance Methods

  • passes() - returns boolean
  • fails() - returns boolean
  • first(attributename) - returns first error message for _string attributename, or _null if no error message exists

See SpecRunner.html for Jasmine tests and examples

0.5.1

11 years ago

0.5.0

11 years ago

0.4.0

11 years ago

0.3.3

11 years ago

0.3.2

11 years ago

0.3.1

11 years ago

0.3.0

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago