Skip to content

validator.js

A JavaScript library for checking and cleaning up strings, like emails, dates, and URLs.

Stars
23.7k
Forks
2.5k
Licence
MIT
Language
JavaScript
Last update
2 months ago
Type
Library

What it is

validator.js is a JavaScript library that provides many functions for checking whether a string matches a format, such as an email address, a date, or a credit card number, and for sanitizing strings. It is installed through npm and can be used on a server or in a browser. The README states it only works on strings, so other input must be converted to a string first.

  • Check that a user-entered email address looks valid with isEmail
  • Confirm a date string falls before or after a given date with isBefore or isAfter
  • Verify that a text field contains only letters or letters and numbers for a given locale with isAlpha or isAlphanumeric
  • Check whether a string is a valid credit card number for a chosen provider with isCreditCard

Great for

  • JavaScript developers validating form or API input on Node.js
  • Developers who need checks like isEmail or isDate without writing regular expressions themselves
  • Projects that want to import only the individual validators they use
  • Browser projects that load a standalone script or CDN file

Not ideal for

  • Anyone who needs validation of non-string data such as numbers or objects, since the README says non-string input causes an error
  • Non-JavaScript projects, since the library is written for JavaScript and npm
  • Non-developers, since it is a code library with no interface
Step-by-step guide: how to use validator.jsInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js or a browser environment

    Install with npm

    npm i validator
  2. 2

    Run it

    • Install the package with npm i validator
    • In a Node.js file, add var validator = require('validator');
    • Call a check such as validator.isEmail('foo@bar.com'), which returns true
  3. 3

    Get the most out of it

    • Import single validators such as validator/lib/isEmail to keep the code small
    • Use the options objects on functions like isDate or isCurrency to adjust the rules
    • Use the tree-shakeable ES imports from validator/es/lib when bundling for the browser

Downloads

Strengths

  • Covers a wide range of common string checks in one package
  • Lets you import only the validators you need to keep bundles smaller
  • Works in both server-side Node.js code and in the browser

Trade-offs

  • Accepts only strings, so inputs must be converted before checking
  • The README excerpt does not show how strict each check is, so results should be tested against your own rules

How it compares

ProjectStarsTypeLevelUpdatedBest for
validator.js (this)23.7kLibrarybeginner2 months agoJavaScript developers validating form or API input on Node.js
zod44.2kLibrarybeginner7 days agoTypeScript developers who want runtime checks that match their static types
yup23.7kLibrarybeginner7 days agoDevelopers validating form or API input in JavaScript or TypeScript
vee-validate11.3kLibraryintermediate8 months agoVue developers who need form validation without writing it from scratch
class-validator11.9kLibrarybeginner8 months agoTypeScript developers validating request bodies or form data in Node.js or the browser
pydantic29.3kLibrarybeginner4 days agoPython developers who already use type hints and want runtime checks on incoming data

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.