diff --git a/src/Rules/Length.php b/src/Rules/Length.php new file mode 100644 index 0000000..66365e7 --- /dev/null +++ b/src/Rules/Length.php @@ -0,0 +1,33 @@ +requireParameters($this->fillableParams); + + $this->requireParameters($this->fillableParams); + + $length = (int) $this->parameter('length'); + + return strlen((string) $value) == $length; + } +} diff --git a/src/Validator.php b/src/Validator.php index dfa19c5..71e65ce 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -162,6 +162,7 @@ protected function registerBaseValidators() 'defaults' => new Rules\Defaults, 'default' => new Rules\Defaults, // alias of defaults 'nullable' => new Rules\Nullable, + 'length' => new Rules\Length, ]; foreach ($baseValidator as $key => $validator) {