0.3.1 • Published 11 years ago

validotron v0.3.1

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

Validotron

Build Status

Validator offers Rails-style validations on JavaScript objects or any data you throw at it.

var validotron = require(validotron);

function Hat(name, size, colour, terms) {
  this.name = name || undefined;
  this.size = size || undefined;
  this.colour = colour || undefined;
  this.terms = terms || undefined;

  this.validate = function() {
    this.errors = undefined;
    var validation = new validotron({ 
      name: { 
        data: this.name, 
        format: {
          with:"[A-Z]"
        }
      }, 
      size: {
        data: this.size,
        numericality: true
      },
      color: {
        data: this.colour,
        presence: true
      },
      terms: {
        data: this.terms,
        acceptance: true
      }
    });
    this.errors = validation.errors;
  }
}

var hatObject = new Hat('*&^%$#', 'big', undefined, '0');
hatObject.validate();
hatObject.errors;

{ name: [ 'is invalid' ],
  size: [ 'is not a number' ],
  color: [ 'can\'t be blank' ],
  terms: [ 'must be accepted' ] }

Installation

npm install validotron

Usage

var validotron = require('validotron');
0.3.1

11 years ago

0.3.0

12 years ago

0.1.2

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.1

12 years ago