Iban

This constraint is used to ensure that a bank account number has the proper
format of an International Bank Account Number (IBAN). IBAN is an
internationally agreed means of identifying bank accounts across national
borders with a reduced risk of propagating transcription errors.

# config/validator/validation.yamlApp\Entity\Transaction:properties:bankAccountNumber:-Iban:message:This is not a valid International Bank Account Number (IBAN).

XML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

<!-- config/validator/validation.xml --><?xml version="1.0" encoding="UTF-8" ?><constraint-mappingxmlns="http://symfony.com/schema/dic/constraint-mapping"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"><classname="App\Entity\Transaction"><propertyname="bankAccountNumber"><constraintname="Iban"><optionname="message">
This is not a valid International Bank Account Number (IBAN).
</option></constraint></property></class></constraint-mapping>

PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// src/Entity/Transaction.phpnamespaceApp\Entity;useSymfony\Component\Validator\Mapping\ClassMetadata;useSymfony\Component\Validator\ConstraintsasAssert;classTransaction{protected$bankAccountNumber;publicstaticfunctionloadValidatorMetadata(ClassMetadata$metadata){$metadata->addPropertyConstraint('bankAccountNumber',newAssert\Iban(['message'=>'This is not a valid International Bank Account Number (IBAN).',]));}}

Note

As with most of the other constraints, null and empty strings are
considered valid values. This is to allow them to be optional values.
If the value is mandatory, a common solution is to combine this constraint
with NotBlank.