Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #35 from lgomezma/master

Added number coercion for validatesLength qualifier arguments.
  • Loading branch information...
commit 70b2052ecf094524bd033f1bba385b5942bcf7a4 2 parents d954282 + 8ede659
@mde mde authored
Showing with 15 additions and 0 deletions.
  1. +15 −0 lib/validators.js
View
15 lib/validators.js
@@ -80,6 +80,11 @@ var validators = {
if (!val) {
return rule.message || 'Field "' + name + '" is required.';
}
+ if(Math.round(qual)==qual){
+ qual = Math.round(qual);
+ }else if(typeof qual !== 'undefined' && typeof qual !== 'object'){
+ throw new Error('qualifier at validatesLength needs to be a number or an object');
+ }
if (typeof qual == 'number') {
if (val.length != qual) {
//return rule.message || 'Field "' + name + '" must be ' + qual +
@@ -89,6 +94,16 @@ var validators = {
}
}
else {
+ if(Math.round(qual.min)==qual.min){
+ qual.min = Math.round(qual.min);
+ }else if(typeof qual.min !== 'undefined'){
+ throw new Error('min property of qualifier at validatesLength needs to be a number');
+ }
+ if(Math.round(qual.max)==qual.max){
+ qual.max = Math.round(qual.max);
+ }else if(typeof qual.max !== 'undefined'){
+ throw new Error('max property of qualifier at validatesLength needs to be a number');
+ }
if (typeof qual.min == 'number' && val.length < qual.min) {
//return rule.message || 'Field "' + name + '" must be at least ' +
// qual.min + ' characters long.';
Please sign in to comment.
Something went wrong with that request. Please try again.