W
W
WebDev2021-07-28 12:54:46
symfony
WebDev, 2021-07-28 12:54:46

Is it possible to validate a number in Symfony?

I need to add a number check.

/**
     * @var int|null
     *
     * @Assert\NotBlank
     * @Serializer\Type(name="integer")
     */
    private ?int $order = null;


The code above first converts the input to a number and then validates. This means that I can pass in an empty string, false, or an empty array and it will happily convert to a number. Is it possible to somehow check that the user is passing a number?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sl0, 2021-07-28
@kirill-93

@Assert\Type(type="integer")
Accordingly, IntegerType must be specified in the form

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question