talira

validator.js

String validators and sanitizers for JavaScript

open sourceMITfree

validator.js is a JavaScript library of string validators and sanitizers for Node.js and the browser. It checks whether a string is an email address, URL, IP address, UUID, credit card number, IBAN, ISBN, JWT, date, mobile phone number, postal code, strong password and many other formats, and sanitizes strings by trimming, escaping and normalizing them. It works on strings only, and each validator can be imported on its own or as tree-shakeable ES modules.

Problems it solves

  • check whether a string is a valid email address in JavaScript
  • validate a phone number or postal code for a given country in Node.js
  • sanitize and normalize user input strings in a web form

Features

  • validators for email, URL, IP, UUID, IBAN, ISBN, credit card and many other formats
  • locale-aware checks for mobile phone numbers, postal codes and identity cards
  • sanitizers such as trim, escape, normalizeEmail and whitelist
  • import single validators or tree-shakeable ES modules
  • runs in Node.js and in the browser

Limitations

  • It validates and sanitizes strings only: anything else passed in throws an error.1
  • XSS sanitization was removed from the library; its README points to DOMPurify or xss-filters instead.1

Alternatives

The same job

These do what validator.js does.

  1. express-validator Express middleware that validates and sanitizes requests with validator.js

Compare validator.js with the top 3