A simple node module for validating request parameters and objects.
This module supports custom error messages.
Installation
$ npm install form-validator-node
Usage
A simple example showing object validation.
var validator = ; var userInfoValidations = firstName: "type: string | required:true | minlength:3 | maxlength: 40 | pattern:/^[A-Za-z0-9]*$/" lastName: "type: string | minlength:1 | maxlength: 40 | pattern:/^[A-Za-z0-9]*$/" userName: "type: string | required:true | minlength:6 | maxlength:30 | pattern:/^[A-Za-z0-9_]*$/" age: "required:true | type:number | minvalue:13 | maxvalue:70" var userObject = firstName: "daniel" lastName: "radcliffe" userName: "DanJRadcliffeNL" age: 30var options = {};
A simple express example showing login form validation.
var validator = ; app
A simple express example showing login form validation using promises.
var validator = ; app
A simple express example showing login form validation with custom error messages.
var validator = ; app
Options
deleteOtherFields
Returns only fields in validation object if "deleteOtherFields" value is true. Else returns all fields. Default value is true.
Available Validations
required: true : <optional error message>
Value in the object must exist for given field.
type: <string | number | boolean | list>: <optional error message>
Value in the object must be the given type.
minvalue: <number>: <optional error message>
This will be used for number data types.Field value in the object should not be lower than the specified value.
maxvalue: <number>: <optional error message>
This will be used for number data types.Field value in the object should not be greater than the specified value.
minlength: <number>: <optional error message>
Length of the field value in the object should not be lower than the specified value.
maxlength: <number>: <optional error message>
Length of the field value in the object should not be greater than the specified value.
pattern: <regex>: <optional error message>
Field value must follow given pattern.