From cd4d1d25876e4bac9c50aab8cd2855c39a80d787 Mon Sep 17 00:00:00 2001 From: Renan Gautier Date: Thu, 16 Jun 2016 18:26:00 +0200 Subject: [PATCH] Add uppercase and lowercase validators Add two validators : "uppercase" and "lowercase". String must contain 1 or more lower or upper chars --- .../Domain/Validator/AbstractValidator.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Classes/Domain/Validator/AbstractValidator.php b/Classes/Domain/Validator/AbstractValidator.php index 79c00ae..d408c5d 100644 --- a/Classes/Domain/Validator/AbstractValidator.php +++ b/Classes/Domain/Validator/AbstractValidator.php @@ -215,6 +215,20 @@ protected function validateMustInclude($value, $validationSettingList) } break; + // value must include uppercase letter + case 'uppercase': + if (!$this->stringContainsUpperCharacter($value)) { + $isValid = false; + } + break; + + // value must include lowercase letter + case 'lowercase': + if (!$this->stringContainsLowerCharacter($value)) { + $isValid = false; + } + break; + default: } } @@ -315,6 +329,28 @@ protected function stringContainsSpaceCharacter($value) return (strpos($value, ' ') !== false); } + /** + * String contains space character? + * + * @param string $value + * @return bool + */ + protected function stringContainsUpperCharacter($value) + { + return (strlen(preg_replace('/[A-Z]/', '', $value)) !== strlen($value)); + } + + /** + * String contains space character? + * + * @param string $value + * @return bool + */ + protected function stringContainsLowerCharacter($value) + { + return (strlen(preg_replace('/[a-z]/', '', $value)) !== strlen($value)); + } + /** * Validation for checking if values are in a given list *