express-validator
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -34,3 +34,4 @@ /* | ||
// route params like /user/:id | ||
if (this.params && this.params.hasOwnProperty(name) && undefined !== this.params[name]) { | ||
if (this.params && this.params.hasOwnProperty(name) && | ||
undefined !== this.params[name]) { | ||
return this.params[name] = value; | ||
@@ -58,4 +59,9 @@ } | ||
// 'login.username' = ['login', 'username'] | ||
// For regex matches you can access the parameters using numbers. | ||
if (!Array.isArray(param)) { | ||
param = param.split('.').filter(function(e){return e != '';}); | ||
param = typeof param === 'number' ? | ||
[param] : | ||
param.split('.').filter(function(e){ | ||
return e !== ''; | ||
}); | ||
} | ||
@@ -125,3 +131,4 @@ | ||
this.str = str; | ||
self.updateParam(param, str); // Replace the param with the filtered version | ||
// Replace the param with the filtered version | ||
self.updateParam(param, str); | ||
}; | ||
@@ -128,0 +135,0 @@ return filter.sanitize(this.param(param)); |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"homepage": "https://github.com/ctavan/express-validator", | ||
@@ -12,0 +12,0 @@ "repository": { |
@@ -153,6 +153,22 @@ # express-validator | ||
### Regex routes | ||
Express allows you to define regex routes like: | ||
```javascript | ||
app.get(/\/test(\d+)/, function() {}); | ||
``` | ||
You can validate the extracted matches like this: | ||
```javascript | ||
req.assert(0, 'Not a three-digit integer.').len(3, 3).isInt(); | ||
``` | ||
## Changelog | ||
### v0.2.4 | ||
- Support for regex routes (@Cecchi) | ||
### v0.2.3 | ||
@@ -159,0 +175,0 @@ - Fix checkHeader() (@pimguilherme) |
@@ -19,2 +19,3 @@ // Sample app | ||
self.app.get(/\/test(\d+)/, self.validation); | ||
self.app.get('/:testparam?', self.validation); | ||
@@ -21,0 +22,0 @@ self.app.post('/:testparam?', self.validation); |
17781
13
391
211
4