Created
February 26, 2012 12:25
-
-
Save cloudaice/1916426 to your computer and use it in GitHub Desktop.
validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var check = require('validator').check, | |
sanitize = require('validator').sanitize | |
//Validate | |
check('test@email.com').len(6, 64).isEmail(); //Methods are chainable | |
check('abc').isInt(); //Throws 'Invalid integer' | |
check('abc', 'Please enter a number').isInt(); //Throws 'Please enter a number' | |
check('abcdefghijklmnopzrtsuvqxyz').is(/^[a-z]+$/); | |
//Sanitize / Filter | |
var int = sanitize('0123').toInt(); //123 | |
var bool = sanitize('true').toBoolean(); //true | |
var str = sanitize(' \s\t\r hello \n').trim(); //'hello' | |
var str = sanitize('aaaaaaaaab').ltrim('a'); //'b' | |
var str = sanitize(large_input_str).xss(); | |
var str = sanitize('<a>').entityDecode(); //'<a>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment