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

easy-form-validations

v1.0.5

Published

A simple collection of reusable form validation rules for JavaScript/TypeScript

Readme

📦 easy-form-validations

A lightweight and reusable collection of form validation rules for JavaScript & TypeScript.
Designed to make form validation simple, declarative, and reusable for any project (React, Node.js, Vanilla JS).


🚀 Installation

npm install easy-form-validations

✨ Features

  • 🔹 Ready-to-use rules (required, minLength, validEmail, strongPassword, etc.)
  • 🔹 Works with strings, numbers, dates, email, and password
  • 🔹 Supports custom rules (regex, custom, oneOf)
  • 🔹 Framework-agnostic (Vanilla JS, TS, React, Next.js, Node.js)
  • 🔹 Built-in React hook: useFormValidation 🚀

⚡ Quick Start

1️⃣ Single Field Validation

import { required, validEmail } from "easy-form-validations";

const email = "[email protected]";

const rules = [required(), validEmail()];

rules.forEach(rule => {
  if (!rule.validate(email)) {
    console.log("❌", rule.message);
  }
});
// ✅ No errors

2️⃣ Validating an Entire Form

import { validateForm, required, validEmail, minLength, strongPassword } from "easy-form-validations";

const formValues = {
  firstName: "John",
  email: "[email protected]",
  password: "weakpass"
};

const rules = {
  firstName: [required()],
  email: [required(), validEmail()],
  password: [required(), minLength(8), strongPassword()]
};

const errors = validateForm(formValues, rules);

console.log(errors);
// { password: "Password must contain uppercase, lowercase, number and special character" }

3️⃣ Using with React (Recommended)

import React from "react";
import { useFormValidation, required, validEmail, minLength, strongPassword } from "easy-form-validations";

function SignupForm() {
  const { values, errors, handleChange, validateForm } = useFormValidation({
    firstName: "",
    email: "",
    password: ""
  });

  const rules = {
    firstName: [required()],
    email: [required(), validEmail()],
    password: [required(), minLength(8), strongPassword()]
  };

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    if (validateForm(rules)) {
      alert("✅ Form submitted successfully!");
    }
  };

  return (
    <form onSubmit={handleSubmit} style={{ maxWidth: "400px" }}>
      <div>
        <label>First Name</label><br />
        <input name="firstName" value={values.firstName} onChange={handleChange} />
        {errors.firstName && <p style={{ color: "red" }}>{errors.firstName}</p>}
      </div>

      <div>
        <label>Email</label><br />
        <input name="email" value={values.email} onChange={handleChange} />
        {errors.email && <p style={{ color: "red" }}>{errors.email}</p>}
      </div>

      <div>
        <label>Password</label><br />
        <input type="password" name="password" value={values.password} onChange={handleChange} />
        {errors.password && <p style={{ color: "red" }}>{errors.password}</p>}
      </div>

      <button type="submit">Submit</button>
    </form>
  );
}

📖 API Reference

📝 Text Rules

| Rule | Description | Example | |------|-------------|---------| | required(message?) | Field must not be empty | required("Name required") | | minLength(min, message?) | Minimum characters | minLength(3) | | maxLength(max, message?) | Maximum characters | maxLength(20) | | exactLength(length, message?) | Exact characters | exactLength(10) | | noNumbers(message?) | Disallow numbers | noNumbers() | | noSpecialChars(message?) | Disallow special chars | noSpecialChars() |

🔢 Number Rules

| Rule | Description | |------|-------------| | isNumber() | Must be a number | | minValue(min) | Minimum value | | maxValue(max) | Maximum value | | isInteger() | Must be integer | | isPositive() | Must be positive |

📅 Date Rules

| Rule | Description | |------|-------------| | isDate() | Must be a valid date | | minDate(date) | Must be after given date | | maxDate(date) | Must be before given date | | isFutureDate() | Must be in the future | | isPastDate() | Must be in the past |

📧 Email Rules

  • validEmail(message?)
  • emailDomain(domain, message?)

🔑 Password Rules

  • strongPassword(message?)
  • passwordMatch(field, message?)

🎯 Misc

  • regex(pattern, message?)
  • custom(fn, message)
  • oneOf(options[], message?)

📦 Advanced Example: Custom Rule

import { custom } from "easy-form-validations";

const startsWithA = custom((value) => value.startsWith("A"), "Must start with A");

console.log(startsWithA.validate("Adam")); // true
console.log(startsWithA.validate("John")); // false, "Must start with A"

🧑‍💻 Author

Made with ❤️ to make form handling easy & reusable.
Licensed under MIT.