Introduction
A Nodejs wrapper of validator.js to support validation chaining and messages
Version 1.0.3
- Add
f
as the alias ofprepare
function - Add `x' as the alias of 'eval' function
Features
- Method chaining
- Batch validations with messages and additional info (tag)
- Able to call any validation method of validator.js with options
valid_wrapper //use aliasvalid_wrapperx'Age must be between 10 and 99'
Getting Started
Installation
npm install validator-wrapper
Usage
var valid_wrapper = var data = email : 'trietho@gmail.com' email2: "bademail" firstname: "Triet" lastname: "" age: 1 password: "trietho@gmail.com" password2: "123456" //the default tag is 'danger', set options to change the default tagvalid_wrapperoptionstag: 1 valid_wrapper //this message will bot be included in the validation results //this message will not be included in the validation results //this message will not be included in the validation results lengthmin:3 "Last name must has at least 3 characters" x'Age must be between 10 and 99' 2 console /* ouput [ { "message": "Second email is invalid", "tag": 1 }, { "message": "Last name must has at least 3 characters", "tag": 1 }, { "message": "Password must be different from email", "tag": "warning" }, { "message": "Password contains letters a-zA-Z only", "tag": 1 }, { "message": "Passwords do not match", "tag": 1 }, { "message": "Age must be between 10 and 99", "tag": 2 }, { "message": "Notexist must be exist :)", "tag": 1 }]*/
API references
functions
pick(content)
: set the first content for validating and clear existing messagespickNext(content)
: set the next content for validating and keep existing messageslength(options, message[, tag])
: if not valid, add the message into validation resultsemail(message[,tag])
: if not email, add the message into validation resultsempty(message[, tag])
: if empty, add the message into validation results, and ignore other validations untilpickNext
equals(target, message[, tag])
diff(target, message[, tag])
custom(condition, message[, tag])
: if condition is true, add the message into validation resultsprepare(method, options)
: selecta method of validatorjs
and its options that to be executed ineval
method- Alias:
f
function
- Alias:
eval(message[, tag])
: execute themethod
defined in theprepare
function and add the message into validation results if the returned value of validator is false- Alias:
x
function
- Alias:
fields
messages
contains the validation resultsvalidator
direct access to validatorjs module