Skip to content

Commit a848e7b

Browse files
committed
Merge pull request #2521 from sprain/IbanConstraint
Added Iban constraint documentation
2 parents ea25d7c + 330b388 commit a848e7b

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

reference/constraints.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Validation Constraints Reference
3838

3939
constraints/CardScheme
4040
constraints/Luhn
41+
constraints/Iban
4142

4243
constraints/Callback
4344
constraints/All

reference/constraints/Iban.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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

reference/constraints/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Financial Constraints
5555

5656
* :doc:`CardScheme </reference/constraints/CardScheme>`
5757
* :doc:`Luhn </reference/constraints/Luhn>`
58+
* :doc:`Iban </reference/constraints/Iban>`
5859

5960
Other Constraints
6061
~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)