Permalink
Browse files

Updated README

  • Loading branch information...
1 parent 3e34495 commit 63d2230c27ab3630c40c3a99a04656e8f7545edf @chriso committed Dec 22, 2010
Showing with 24 additions and 0 deletions.
  1. +24 −0 README.md
View
@@ -14,6 +14,7 @@ To use the library in the browser, include `validator-min.js`
//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
@@ -63,6 +64,29 @@ To use the library in the browser, include `validator-min.js`
entityEncode()
xss(is_image) //Remove common xss attack vectors
+## Web development
+
+Often it's more desirable to check or automatically sanitize parameters by name (rather than the string). See this gist (https://gist.github.com/752126) for instructions on binding the library to the `request` prototype.
+
+Example `http://localhost:8080/?zip=12345&foo=1&textarea=large_string`
+
+ get('/', function (req, res) {
+ req.onValidationError(function() {
+ //Redirect the user..
+ });
+
+ //Validate user input
+ req.check('zip', 'Please enter a valid ZIP code').len(4,5).isInt();
+ req.check('email', 'Please enter a valid email').len(6,64).isEmail();
+ req.checkHeader('referer').contains('localhost');
+
+ //Sanitize user input
+ req.sanitize('textarea').xss();
+ req.sanitize('foo').toBoolean();
+
+ //etc.
+ });
+
## Extending the library
When adding to the Validator prototype, use `this.str` to access the string and `this.error(this.msg || default_msg)` when the string is invalid

0 comments on commit 63d2230

Please sign in to comment.