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

connect-forms-validator

v1.0.3

Published

Connect form middleware

Readme

Connect form middleware

Quickstart

Install

npm install --save connect-forms-validator

Usage

var formMiddleware = require('connect-forms-validator');

someForm = formMiddleware(
  form.field("username").required()
);

app.any('/login', someForm, function(req, res){

  if (req.form.isValid()){
  	// process req.form.data
  }
  res.render('login.html');

});

API

Form Middleware

The form middleware is the main entrypoint to the connect-forms-validator package.

var formMiddleware = require('connect-forms-validator');

formMiddleware(field, [, fields, ...])

The form middleware accepts a variable number of fields as a constructor

formMiddleware.use(callback)

Mount middleware to this form like express.Router. Unlike the Router formMiddleware.use only takes one callback argument.

formMiddleware.success(callback)

Mount middleware to this form. The success middleware will only be called when a non GET,HEAD,OPTIONS method is used and all of the field validators pass.

formMiddleware.flash(category='danger')

Flash an error message if any of the fields are invalid.

Form Object

Form objects are set on the req oject by the form middleware.

req.form

Form.data

The modified field data that has been sanitied by field middleware

Form.rawData

The unmodified field data

Form.errors

An object that contains {fieldname: [errorMessage, ... ]} entries

Form.isValid()

Returns true if form.errors is not empty

Form.addError(key, message)

Returns true if form.errors is not empty

Fields

The Field object has a middleware stack and can 'use' middleware itself

Fields can be accessed from the main form template

var form = require('connect-forms-validator');
var field = form.field;

var form.field("username").trim().use(function(req, res, next, keyname, value){
})

field.use(callback)

callback

A function with the signature callback(req, res, next, key, value)

If next is called with a string, the middleware processing will stop for this field and form.addError(key, message) will be called.

field.bool()

Ensure the field is a boolean value

field.trim()

Call string trim method on the value

field.required([message])

Flag an error if the field is not given

field.flash()

Flash error if the field has an error

field.is(re [, message])

Match the field value against a regular expression

field.default(value)

Set the default value for this field

choices = function(choices [, message])

Restrict this field to an array of choices