|
| 1 | +Iban |
| 2 | +==== |
| 3 | + |
| 4 | +This constraint is used to ensure that a bank account number has the proper format of |
| 5 | +an `International Bank Account Number (IBAN)`_. IBAN is an internationally agreed means |
| 6 | +of identifying bank accounts across national borders with a reduced risk of propagating |
| 7 | +transcription errors. |
| 8 | + |
| 9 | ++----------------+-----------------------------------------------------------------------+ |
| 10 | +| Applies to | :ref:`property or method<validation-property-target>` | |
| 11 | ++----------------+-----------------------------------------------------------------------+ |
| 12 | +| Options | - `message`_ | |
| 13 | ++----------------+-----------------------------------------------------------------------+ |
| 14 | +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Iban` | |
| 15 | ++----------------+-----------------------------------------------------------------------+ |
| 16 | +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\IbanValidator` | |
| 17 | ++----------------+-----------------------------------------------------------------------+ |
| 18 | + |
| 19 | +Basic Usage |
| 20 | +----------- |
| 21 | + |
| 22 | +To use the Iban validator, simply apply it to a property on an object that |
| 23 | +will contain an International Bank Account Number. |
| 24 | + |
| 25 | +.. configuration-block:: |
| 26 | + |
| 27 | + .. code-block:: yaml |
| 28 | +
|
| 29 | + # src/Acme/SubscriptionBundle/Resources/config/validation.yml |
| 30 | + Acme\SubscriptionBundle\Entity\Transaction: |
| 31 | + properties: |
| 32 | + bankAccountNumber: |
| 33 | + - Iban: |
| 34 | + message: This is not a valid International Bank Account Number (IBAN). |
| 35 | +
|
| 36 | + .. code-block:: xml |
| 37 | +
|
| 38 | + <!-- src/Acme/SubscriptionBundle/Resources/config/validation.xml --> |
| 39 | + <class name="Acme\SubscriptionBundle\Entity\Transaction"> |
| 40 | + <property name="bankAccountNumber"> |
| 41 | + <constraint name="Iban"> |
| 42 | + <option name="message">This is not a valid International Bank Account Number (IBAN).</option> |
| 43 | + </constraint> |
| 44 | + </property> |
| 45 | + </class> |
| 46 | +
|
| 47 | + .. code-block:: php-annotations |
| 48 | +
|
| 49 | + // src/Acme/SubscriptionBundle/Entity/Transaction.php |
| 50 | + namespace Acme\SubscriptionBundle\Entity\Transaction; |
| 51 | + |
| 52 | + use Symfony\Component\Validator\Constraints as Assert; |
| 53 | +
|
| 54 | + class Transaction |
| 55 | + { |
| 56 | + /** |
| 57 | + * @Assert\Iban(message = "This is not a valid International Bank Account Number (IBAN).") |
| 58 | + */ |
| 59 | + protected $bankAccountNumber; |
| 60 | + } |
| 61 | +
|
| 62 | + .. code-block:: php |
| 63 | +
|
| 64 | + // src/Acme/SubscriptionBundle/Entity/Transaction.php |
| 65 | + namespace Acme\SubscriptionBundle\Entity\Transaction; |
| 66 | + |
| 67 | + use Symfony\Component\Validator\Mapping\ClassMetadata; |
| 68 | + use Symfony\Component\Validator\Constraints as Assert; |
| 69 | +
|
| 70 | + class Transaction |
| 71 | + { |
| 72 | + protected $bankAccountNumber; |
| 73 | +
|
| 74 | + public static function loadValidatorMetadata(ClassMetadata $metadata) |
| 75 | + { |
| 76 | + $metadata->addPropertyConstraint('bankAccountNumber', new Assert\Iban(array( |
| 77 | + 'message' => 'This is not a valid International Bank Account Number (IBAN).', |
| 78 | + ))); |
| 79 | + } |
| 80 | + } |
| 81 | +
|
| 82 | +Available Options |
| 83 | +----------------- |
| 84 | + |
| 85 | +message |
| 86 | +~~~~~~~ |
| 87 | + |
| 88 | +**type**: ``string`` **default**: ``This is not a valid International Bank Account Number (IBAN).`` |
| 89 | + |
| 90 | +The default message supplied when the value does not pass the Iban check. |
| 91 | + |
| 92 | +.. _`International Bank Account Number (IBAN)`: http://en.wikipedia.org/wiki/International_Bank_Account_Number |
0 commit comments