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 🙏

© 2025 – Pkg Stats / Ryan Hefner

form-validation-lib-js

v2.1.5

Published

A comprehensive JavaScript form validation library

Downloads

22

Readme

Form-Validation-Library JS/TS

  • 🎉 A comprehensive TypeScript/JavaScript form validation library.

npm version License: MIT TypeScript

Quick Start

npm install form-validation-lib-js

Features

  • 🚀 Zero dependencies
  • 💪 TypeScript support
  • ⚡ Tree-shakeable
  • 🔄 Async validation
  • 🎯 Custom validators

Basic Usage

import { validateEmail, validatePassword, validatePhone_IN } from 'form-validation-lib-js';

// Email validation
const isValidEmail = validateEmail('[email protected]'); // true

// Password validation
const isValidPassword = validatePassword('StrongPass1!'); // true

// Phone Number validation
const isValdPhone_IN = validatePhone_IN('+919876543210'); // true

React Integration:

import React, { useState } from 'react';
import { FormValidator } from 'form-validation-lib-js';

const SignInForm = () => {
  const [formData, setFormData] = useState({
    email: '',
    password: ''
  });
  const [errors, setErrors] = useState({});

  const validator = new FormValidator();

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();

    const validationSchema = {
      email: [{ type: 'email', message: 'Invalid email' }],
      password: [{ type: 'password', message: 'Weak password' }]
    };

    const result = await validator.validateForm(formData, validationSchema);
    if (!result.isValid) {
      setErrors(result.errors.reduce((acc, error) => ({
        ...acc,
        [error.field]: error.message
      }), {}));
      return;
    }
    // Process form data
  };

  return (
    <form onSubmit={handleSubmit}>
      <div>
        <input
          type="email"
          value={formData.email}
          onChange={(e) => setFormData({ ...formData, email: e.target.value })}
        />
        {errors.email && <span>{errors.email}</span>}
      </div>

      <div>
        <input
          type="password"
          value={formData.password}
          onChange={(e) => setFormData({ ...formData, password: e.target.value })}
        />
        {errors.password && <span>{errors.password}</span>}
      </div>
      <button type="submit">Sign In</button>
    </form>
  );
};

export default SignInForm;

Custom Validators

const validator = new FormValidator();

// Add custom sync validator
validator.addValidator('username', (value: string) => {
  return /^[a-zA-Z0-9_]{3,16}$/.test(value);
});

// Add custom async validator
validator.addAsyncValidator('uniqueEmail', async (email: string) => {
  const response = await fetch(`/api/check-email?email=${email}`);
  const { isUnique } = await response.json();
  return isUnique;
});

Available Validators:

  • validateEmail(email: string): boolean
  • validatePassword(password: string): boolean
  • validatePhone(phone: string): boolean
  • validatePhone_AU, validatePhone_IN, validatePhone_UK, validatePhone_US(phone: string): boolean
  • validateDate(date: string): boolean
  • validateNumber(value: string, options?: {min?: number, max?: number}): boolean
  • validateURL(url: string): boolean
  • validateIPAddress(ip: string): boolean
  • validateCreditCard(number: string): boolean

TypeScript Support:

import { ValidationSchema, ValidationResult } from 'form-validation-lib-js';

const schema: ValidationSchema = {
  email: [{ type: 'email' }],
  password: [{ type: 'password' }]
};

Contribute

  • Show your ❤️ and support by giving a ⭐
  • Pull requests are welcome! See (CONTRIBUTING.md) for guidelines.

License:

MIT License - (Anurag Singh), see the (LICENSE) file for details