Code Monkey home page Code Monkey logo

pass.js's Introduction

pass.js

Javascript validation module. Runs from server or web, doesn't need a form.

Requires mocha and chai for running tests.

Installation

You can install this module manually by just saving pass.js somewhere in your project and using require or <script> to pull it in.

Installing via npm:

npm install pass.js

Usage

var pass = require('pass.js');

var rules,data,validator;

var first_name = "Billy";
var last_name = "Jones";
var email = "[email protected]";
var url = "http://theninthnode.com";
var password = "123";

rules = [
	["first_name", "required", "first name"], // var name, rules, label for error message (defaults to var name)
	["last_name", "required", "last name"],
	["email", "required,valid_email"],
	["url", "valid_url"],
	["password", "required,min_length:5"]
];

data = {
	first_name: first_name,	
	last_name: last_name,	
	email: email,	
	url: url,	
	password: password,	
};

validator = pass.validate(rules, data);

if(validator.failed()) {
	console.log(validator.message());
}

Available Rules

  • required
  • matches
  • valid_email
  • min_length
  • max_length
  • exact_length
  • greater_than
  • less_than
  • alpha
  • alpha_numeric
  • alpha_dash
  • numeric
  • integer
  • decimal
  • is_natural
  • is_natural_no_zero
  • valid_ip
  • valid_base64
  • valid_credit_card
  • valid_url

Methods

pass.validate(rules, data) // returns this object
pass.failed() // returns BOOL
pass.message() // returns first error message as string
pass.allMessages() // returns array of error message strings

Contributions

Thanks to validate.js for the regex's and messages.

Inspired by Laravel's validator class.

Trim function - http://blog.stevenlevithan.com/archives/faster-trim-javascript

pass.js's People

Contributors

theninthnode avatar

Stargazers

Sreelal C avatar Reggi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.