Skip to content

Commit

Permalink
fix inconsistent length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Feb 27, 2018
1 parent e24adeb commit 63097a1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions code/ZenValidatorConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,20 @@ public function validate($value)
return true;
}

if(function_exists('mb_strlen')) {
$len = mb_strlen(trim($value));
}
else {
$len = strlen(trim($value));
}

switch ($this->type) {
case 'min':
return strlen(trim($value)) >= $this->val1;
return $len >= $this->val1;
case 'max':
return strlen(trim($value)) <= $this->val1;
return $len <= $this->val1;
case 'range':
return strlen(trim($value)) >= $this->val1 && strlen(trim($value)) <= $this->val2;
return $len >= $this->val1 && $len <= $this->val2;
}
}

Expand Down Expand Up @@ -1336,4 +1343,4 @@ public function getDefaultMessage()
break;
}
}
}
}

0 comments on commit 63097a1

Please sign in to comment.