Validator.js supplies chainable checks and cleaners for strings in Node or the browser, covering emails, URLs, cards, dates, and many other formats.
Overview
Validator.js is a JavaScript package focused on validating and sanitizing string inputs. Each function expects a string operand; callers should coerce other types before calling, otherwise the helpers throw.
The project ships a broad catalog of validators for emails, domains, credit cards, currencies, dates, booleans, encodings, government identifiers, blockchain addresses, and locale-aware alphabetic text. Matching sanitizers trim, escape, or normalize user text. Documentation lists option objects per validator, such as strict email host rules or credit-card provider filters.
You can install the full bundle through npm for server code, import individual functions for tree-shaking, load a browser build via script tags or AMD, or pull builds from a CDN. ES module and CommonJS entry points are supported.
Because it operates purely as a library inside application code, there is no standalone server to deploy. Teams typically call it from HTTP handlers, form components, or CLI scripts as part of their own validation layer.
Key features
- Large validator function catalog
- Complementary string sanitizers
- Tree-shakeable ES module imports
- Browser and Node.js usage
- Locale-aware text validators
- Configurable email and URL rules
- Financial and encoding format checks
- CDN and bundler distribution
Use cases
- API request field validation
- HTML form input checking
- Normalizing user-supplied strings
- Payment and identity format gates
- Shared client-server validation rules