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-data-validator

v1.0.14

Published

A helper for working with the HTML5 constraint validation API

Downloads

48

Readme

form-data-validator

A helper for working with the HTML5 constraint validation API. Providing some tools to easily extend or override native html5 form validation.

Installation

Form Data Validator supports npm

npm install form-data-validator

Usage

import FormDataValidator from 'form-data-validator';

Set up your form according to the constraint validation api attributes. Then run your form through the validator.

The easiest way to do that for your forms is to parse your entire page and run each form through the validator. Form Data Validator has a built in function that does this for you.

FormDataValidator.validateAllForms('.js-validate', { /* options */ }); // defaults to 'form'

Alternatively you validate your own form.

FormDataValidator.validateForm('.js-validate', { /* options */ });

Methods

Method | Description --- | --- FormDataValidator.validateForm(form, config) | form can be a selector string or an element FormDataValidator.validateAllForms(forms, config) | forms can be a selector string or an element isValid() | Returns true or false getErrors() | Returns an array containing the id of the bad input and a object representing the validityErrors.

Options

Option | Value --- | --- scrollToFirstError | Default value: true parentSelector | Default value: 'div' errorClass | Default value: 'error' ignoreFields | Default value: '[]' Pass an array of strings representing the name attribute of the field you don't want to validate customTypes | Default value: []Pass an array of objects with a type, rule and optional message property. See example rules | Default value: []Pass an array of objects with a type, rule and optional message property. See example customValidityMessages | Default value: []Pass an array of objects with a error and message property. The error

Examples

customTypes example

You can override the built-in html5 validation rules for input types. This can come in handy to provide a better email validation. By default email@email will validate because this is a valid email address format. You could implement your own email regular expression to override this. I reccomend the excellen validator.js library.

import isEmail from 'validator/lib/isEmail';

FormDataValidator.validateForm('form', { 
  customTypes: [{
    type: 'email',
    rule: field => isEmail(field.value)
  }]
});

This can also be used to provide a regular expression for password input fields, or a specific kind of url input type validation.

rules example

Add extra validation rules. These rules are mapped to your field's id. A few use cases for this would be a password field that must match a password repeat field. For this example to work make sure your password input type has a data-equal-to attribute:

import equals from 'validator/lib/equals';

const form = document.querySelector('form');
FormDataValidator.validateForm(form, {
  rules: [{
    field: '#password',
    rule: field =>
      equals(field.value, form.querySelector(field.dataset.equalTo).value)
  }]
});

Another use case would be validating a chekcbox group where there has to be at least 1 checked input:

const form = document.querySelector('form');
FormDataValidator.validateForm(form, {
  rules: [{
    field: '[type="checkbox"]',
    rule: (field) => {
      const checked = [...form.querySelectorAll('[type="checkbox"]')]
        .find(checkbox => checkbox.checked);
      if (typeof checked !== 'undefined) return true;
      return false;
    }
  }]
});

customValidityMessages example

Useful for overriding the default browser validity messages. The error property is a string that must match one of the ValidityState properties.

const form = document.querySelector('form');
FormDataValidator.validateForm(form, {
  customValidityMessages: [{
    error: 'valueMissing',
    message: 'Hold on! This field needs to be filled in'
  }]
});