<commit_before># validatorjs v0.8.2

[![Build Status](https://travis-ci.org/skaterdav85/validatorjs.png?branch=master)](https://travis-ci.org/skaterdav85/validatorjs)

The validatorjs library makes for easy data validation on both the client and server side. This library was inspired by the Laravel framework's Validator class.

## Setup

#### Browser:
1. Include __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:
Install the Validator package from the NPM registry [https://npmjs.org/package/validatorjs](https://npmjs.org/package/validatorjs)

```
	npm install validatorjs
```

```js
	var Validator = require('validatorjs');
```

## Usage and 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:
```js
	var data = {
		name: 'David',
		email: '<EMAIL>',
		age: 27
	};
	
	var rules = {
		name: 'required',
		email: 'email',
		age: 'min:18'
	};

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

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

#### Example 2:
```js
	var data = {
		name: '',
		email: 'not an email address.com'
	};
	
	var rules = {
		name: 'required|size:3',
		email: 'required|email'
	};

	var validation = new Validator(data, rules);

	validation.fails(); // true
	validation.passes(); // false

	// Error messages
	validation.errors.first('email'); // 'The email format is invalid.'
	validation.errors.get('email'); // returns an array of all email error messages
```

## Validation Rules

####alpha

The field under validation must be entirely alphabetic characters.

####alpha_dash

The field under validation may have alpha-numeric characters, as well as dashes and underscores.

####alpha_num

The field under validation must be entirely alpha-numeric characters.

####different:attribute

The given field must be different than the field under validation.


####email

The field under validation must be formatted as an e-mail address.<commit_msg>updated documentation<commit_after># validatorjs v0.8.2

[![Build Status](https://travis-ci.org/skaterdav85/validatorjs.png?branch=master)](https://travis-ci.org/skaterdav85/validatorjs)

The validatorjs library makes for easy data validation on both the client and server side. This library was inspired by the Laravel framework's Validator class.

## Setup

#### Browser:
1. Include __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:
Install the Validator package from the NPM registry [https://npmjs.org/package/validatorjs](https://npmjs.org/package/validatorjs)

```
	npm install validatorjs
```

```js
	var Validator = require('validatorjs');
```

## Usage and 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:
```js
	var data = {
		name: 'David',
		email: '<EMAIL>',
		age: 27
	};
	
	var rules = {
		name: 'required',
		email: 'email',
		age: 'min:18'
	};

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

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

#### Example 2:
```js
	var data = {
		name: '',
		email: 'not an email address.com'
	};
	
	var rules = {
		name: 'required|size:3',
		email: 'required|email'
	};

	var validation = new Validator(data, rules);

	validation.fails(); // true
	validation.passes(); // false

	// Error messages
	validation.errors.first('email'); // 'The email format is invalid.'
	validation.errors.get('email'); // returns an array of all email error messages
```

## Validation Rules

####accepted

The field under validation must be yes, on, or 1. This is useful for validating "Terms of Service" acceptance.

####alpha

The field under validation must be entirely alphabetic characters.

####alpha_dash

The field under validation may have alpha-numeric characters, as well as dashes and underscores.

####alpha_num

The field under validation must be entirely alpha-numeric characters.

####confirmed

The field under validation must have a matching field of foo_confirmation. For example, if the field under validation is password, a matching password_confirmation field must be present in the input.

####different:attribute

The given field must be different than the field under validation.


####email

The field under validation must be formatted as an e-mail address.
{'fraction_non_alphanumeric': 0.10935601458080195, 'fraction_numerical': 0.0074929121101660594, 'mean_word_length': 4.248671625929862, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '843581', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1396, 'n_words': 567}