M
M
magary42017-08-25 17:43:27
symfony
magary4, 2017-08-25 17:43:27

Why is the form validator not working?

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('postcode', IntegerType::class, [
                'required' => true,
                'attr' => [
                    "min" => "1000",
                    "max" => "99999",
                    'minMessage' => 'min error message'
                    , 'maxMessage' => 'max error message'
                ],
                'constraints' => array(
                    new Constraints\NotBlank(),
                    new Constraints\Type('integer'),
                    new Constraints\Regex(array(
                            'pattern' => '/^[0-9]\d*$/',
                            'message' => 'Please use only positive numbers.'
                        )
                    ),
                    new Constraints\Length(array('min' => 4, 'max' => 5))
                )
            ]);
 }

after submitting an empty field, it gives a message that the field cannot be empty, and when filled with numbers like 12, 123, 1234567,
the form is valid and there are no messages

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question