
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
How to get it
- 1
Install with a package manager
You'll need: Node.js or a browser environment
Install with npm
npm i validator - 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
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
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| validator.js (this) | 23.7k | Library | beginner | 2 months ago | JavaScript developers validating form or API input on Node.js |
| zod | 44.2k | Library | beginner | 7 days ago | TypeScript developers who want runtime checks that match their static types |
| yup | 23.7k | Library | beginner | 7 days ago | Developers validating form or API input in JavaScript or TypeScript |
| vee-validate | 11.3k | Library | intermediate | 8 months ago | Vue developers who need form validation without writing it from scratch |
| class-validator | 11.9k | Library | beginner | 8 months ago | TypeScript developers validating request bodies or form data in Node.js or the browser |
| pydantic | 29.3k | Library | beginner | 4 days ago | Python 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.