npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

form-validator-node

v1.1.0

Published

A simple node module for handling form validations.

Readme

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 = require("form-validator-node");

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: 30
}
var options = {};
validator(userInfoValidations, userObject,options,function(validationErrors, verifiedData){
	if(validationErrors)
	{
		console.log(validationErrors);
	}
})
	

A simple express example showing login form validation.

var validator = require("form-validator-node");

app.post("/login",function(req,res){
   var loginFormValidations = {
   	userName: "required:true | minlength:6 | maxlength:30",
   	password: "minlength:6 | maxlength:50"
   }
   var options = {};
   validator(loginFormValidations, req.body,options,function(validationErrors, verifiedData){
   	if(validationErrors)
   	{
   		res.send(400).send(validationErrors);
   	}
   })
})

A simple express example showing login form validation using promises.

var validator = require("form-validator-node");

app.post("/login",function(req,res){
   var loginFormValidations = {
   	userName: "required:true | minlength:6 | maxlength:30",
   	password: "minlength:6 | maxlength:50"
   }
   var options = {};

   validator(loginFormValidations,req.body,options).then(verifiedData=>{
   	console.log(verifiedData);
   }).catch(validationErrors => {
   	res.send(400).send(validationErrors);
   })

})

A simple express example showing login form validation with custom error messages.

var validator = require("form-validator-node");

app.post("/login",function(req,res){
   var loginFormValidations = {
   	userName: `required:true:Username is a mandatory field, Please fill out the field. | 
   	minlength:6:userName length should be atleast 6 characters. | 
   	maxlength:30:userName lenght exceeds 30 characters.`,
   	password: "minlength:6 | maxlength:50"
   }
   var options = { deleteOtherFields : true };  // Options object will be explained in below sections.
   validator(loginFormValidations, req.body,options,function(validationErrors, verifiedData){
   	if(validationErrors)
   	{
   		res.send(400).send(validationErrors);
   	}
   })
})

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.