<commit_before># validator.js

Powerful objects and strings validation in javascript for Node and the browser

## Version

0.5.8

## Status

[![Build Status](https://travis-ci.org/guillaumepotier/validator.js.png?branch=master)](https://travis-ci.org/guillaumepotier/validator.js)
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/guillaumepotier/validator.js/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

## License

MIT - See LICENSE.md

## Install

`bower install validator.js`

## Run Tests

- On node:
  - `npm install mocha`
  - `npm install expect.js`
  - `mocha tests/server.js`

- On browser:
  - open tests/browser.html in your browser

# Summary

  - [General usage](#general-usage)
  - [Validate string](#validate-a-string)
  - [Validate object](#validate-an-object)
  - [Validation groups](#validation-groups)
  - [Bind constraint to an object](#bind-a-constraint-to-an-object)
  - [Assert definition](#assert-definition)
  - [Constraint definition](#constraint-definition)
  - [Available asserts](#available-asserts)
  - [Collection Assert](#collection-assert)
  - [Callback Assert](#callback-assert)

## General usage

- On node:
```
$ npm install -g validator.js
```
Then
```js
Validator = require( 'validator.js' );
```
- On browser:
```js
<script src="../validator.js"></script>
<script>
    console.log(Validator);
</script>
```

## Validate a string

```js
var Assert = Validator.Assert;

Validator.Validator().validate( 'foo', new Assert().Length( { min: 4 } ) );
Validator.Validator().validate( 'foo', [ new Assert().Length( { min: 4 } ), new Assert().Email() ] );

```
will return `true` if validation passes, a `Violation`'s array otherwise.

## Validate an object

```js
var Validator = Validator.Validator,
    Assert = Validator.Assert,
    Constraint = Validator.Constraint;

var object = {
    name: '<NAME>',
    email: 'wrong<EMAIL>',
    firstname: null,
    phone: null
  },
  constraint = {
    name:      [ new Assert().NotBlank(), new Assert().Length( { min: 4, max: 25 } ) ],
    email:     new Assert().Email(),
    firstname: new Assert().NotBlank(),
    phone:     new Assert().NotBlank()
  };

Validator.validate( object, constraint );
```
will return `true` if validation passes,
`{ email: [ Violation ], firstname: [ Violation ] }` in this case.<commit_msg>- updated wrong README doc Closes #8<commit_after># validator.js

Powerful objects and strings validation in javascript for Node and the browser

## Version

0.5.8

## Status

[![Build Status](https://travis-ci.org/guillaumepotier/validator.js.png?branch=master)](https://travis-ci.org/guillaumepotier/validator.js)
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/guillaumepotier/validator.js/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

## License

MIT - See LICENSE.md

## Install

`bower install validator.js`

## Run Tests

- On node:
  - `npm install mocha`
  - `npm install expect.js`
  - `mocha tests/server.js`

- On browser:
  - open tests/browser.html in your browser

# Summary

  - [General usage](#general-usage)
  - [Validate string](#validate-a-string)
  - [Validate object](#validate-an-object)
  - [Validation groups](#validation-groups)
  - [Bind constraint to an object](#bind-a-constraint-to-an-object)
  - [Assert definition](#assert-definition)
  - [Constraint definition](#constraint-definition)
  - [Available asserts](#available-asserts)
  - [Collection Assert](#collection-assert)
  - [Callback Assert](#callback-assert)

## General usage

- On node:
```
$ npm install -g validator.js
```
Then
```js
Validator = require( 'validator.js' );
```
- On browser:
```js
<script src="../validator.js"></script>
<script>
    console.log(Validator);
</script>
```

## Validate a string

```js
var Assert = Validator.Assert;

Validator.Validator().validate( 'foo', new Assert().Length( { min: 4 } ) );
Validator.Validator().validate( 'foo', [ new Assert().Length( { min: 4 } ), new Assert().Email() ] );

```
will return `true` if validation passes, a `Violation`'s array otherwise.

## Validate an object

```js
var Assert = Validator.Assert,
    Constraint = Validator.Constraint;

var object = {
    name: '<NAME>',
    email: 'wrong@email',
    firstname: null,
    phone: null
  },
  constraint = {
    name:      [ new Assert().NotBlank(), new Assert().Length( { min: 4, max: 25 } ) ],
    email:     new Assert().Email(),
    firstname: new Assert().NotBlank(),
    phone:     new Assert().NotBlank()
  };

new Validator.Validator().validate( object, constraint );
```
will return `true` if validation passes,
`{ email: [ Violation ], firstname: [ Violation ] }` in this case.
{'fraction_non_alphanumeric': 0.1682142085942561, 'fraction_numerical': 0.0058302742388253075, 'mean_word_length': 3.948717948717949, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '6355154', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1501, 'n_words': 368}