From 21254716528c40cfd2b0574f972a8b397faee477 Mon Sep 17 00:00:00 2001 From: Vadim Kharitonov Date: Tue, 16 Sep 2014 01:00:07 +0300 Subject: [PATCH] [Form] max option of Length Constraint --- .../Form/Extension/Validator/ValidatorTypeGuesser.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php index 63d06dca7185..52d25893b936 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php +++ b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php @@ -220,6 +220,10 @@ public function guessPatternForConstraint(Constraint $constraint) switch (get_class($constraint)) { case 'Symfony\Component\Validator\Constraints\Length': if (is_numeric($constraint->min)) { + if (is_numeric($constraint->max)) { + return new ValueGuess(sprintf('.{%s,%s}', (string) $constraint->min, (string) $constraint->max), Guess::LOW_CONFIDENCE); + } + return new ValueGuess(sprintf('.{%s,}', (string) $constraint->min), Guess::LOW_CONFIDENCE); } break; @@ -234,6 +238,10 @@ public function guessPatternForConstraint(Constraint $constraint) case 'Symfony\Component\Validator\Constraints\Range': if (is_numeric($constraint->min)) { + if (is_numeric($constraint->max)) { + return new ValueGuess(sprintf('.{%s,%s}', strlen((string) $constraint->min), strlen((string) $constraint->max)), Guess::LOW_CONFIDENCE); + } + return new ValueGuess(sprintf('.{%s,}', strlen((string) $constraint->min)), Guess::LOW_CONFIDENCE); } break;