
validator.js
#Knowledge Base#Miscellaneous
Top 15 recommendations to protect your business from email-borne threats with Security Gateway.
This Library Validates and Sanitizes Strings Only
If you're uncertain whether your input is a string, you can convert it by using input + ''. If you pass anything other than a string, it will result in an error.
Installation and Usage Overview
Installation and Usage
Server-side usage
To install the library, use the following command:
npm install validator
Using CommonJS (No ES6):
var validator = require('validator');
validator.isEmail('foo@bar.com'); //=> true
Using ES6:
import validator from 'validator';
Alternatively, you can import just a specific part of the library:
import isEmail from 'validator/lib/isEmail';
For tree-shakeable ES imports:
import isEmail from 'validator/es/lib/isEmail';
Client-side usage
The library can be loaded in different ways
The library can be loaded either as a standalone script or by using an AMD-compatible loader. You can include it in your HTML with the following script tag:
The library can also be installed via Bower
You can also install the library using Bower with the following command:
$ bower install validator-js
CDN
To include the library via a CDN, use the following script tag:
Validators
Below is a list of the available validators:
Validator Description
contains(str, seed [, options]) Checks if the string contains the specified seed.