Symfony2 validator Length with min parameter allows empty value

Marin Bînzari

Today I found something strange about Symfony >=2.3 validators. I you use

$metadata->addPropertyConstraint('body', new Length(array('min' => 50)));

it allows empty inputs. I don't think it should do this or am I wrong?

rpg600

This is the expected behaviour.

Just think about the different use cases: a phone number can be optional, but if the user has entered a phone number, it should be at least 10 characters.

So you need to combine your Length constraint with a NotNull/NotBlank constraint.

See https://github.com/symfony/symfony/issues/10221#issuecomment-34769066 for more explanation.

Btw : there is actually a brainstorming about empty string handling https://github.com/symfony/symfony/issues/11956.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Symfony2 validator Length with min parameter allows empty value

From Dev

Symfony2 choice field : empty value

From Dev

Symfony2 POST variable parameter empty in Internet Explorer

From Dev

Symfony2: Entity form field with empty value

From Dev

Symfony2 choice field required with empty_value

From Dev

Symfony2 choice field required with empty_value

From Dev

Symfony 2 Email Validator Null Value

From Dev

Symfony 2 Email Validator Null Value

From Dev

symfony2 custom validator FatalErrorException

From Dev

Symfony2 Validator Message depend on group

From Dev

Symfony2 validator wants to be an instance of ValidatorInterface

From Dev

Symfony2 LiipFunctionalTestBundle overriding @validator service

From Dev

Symfony2 : Override Validator of a Bundle

From Dev

Symfony2 Validator Message depend on group

From Dev

Creating a custom validator as a service in Symfony2

From Dev

symfony2 empty jsonResponse

From Dev

How can I pass nested parameter value to service in Symfony2

From Dev

Angular 2 Pass parameter to a validator function

From Dev

Angular 2 Pass parameter to a validator function

From Dev

Silex/Symfony Form validator : ensure a value is unique

From Dev

Symfony2 Remove empty field in FormType

From Dev

empty inherited entity Symfony2

From Dev

Symfony2 flashBag empty array

From Dev

Empty/Invalid token in Symfony2

From Dev

Symfony2 getData is returning empty fields

From Dev

Symfony QueryParam with empty value

From Dev

How to use the symfony2 validator component in a legacy PHP project?

From Dev

Symfony2 Validator message: Which variables are available?

From Dev

Symfony2 how to validate unique email using validator component

Related Related

HotTag

Archive