From 63097a17a2a93cdaea9e503c44dbcff341047f0c Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 27 Feb 2018 16:22:57 +0100 Subject: [PATCH] fix inconsistent length validation --- code/ZenValidatorConstraint.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/code/ZenValidatorConstraint.php b/code/ZenValidatorConstraint.php index d596b05..63a5ee4 100644 --- a/code/ZenValidatorConstraint.php +++ b/code/ZenValidatorConstraint.php @@ -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; } } @@ -1336,4 +1343,4 @@ public function getDefaultMessage() break; } } -} \ No newline at end of file +}