Skip to content

Commit 7911fe1

Browse files
mvhirschxabbuh
authored andcommitted
[Validator] added BIC validator
1 parent 6383740 commit 7911fe1

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

reference/constraints.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Validation Constraints Reference
5050
constraints/Currency
5151
constraints/Luhn
5252
constraints/Iban
53+
constraints/Bic
5354
constraints/Isbn
5455
constraints/Issn
5556

reference/constraints/Bic.rst

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Bic
2+
===
3+
4+
.. versionadded:: 2.8
5+
The Bic constraint was introduced in Symfony 2.8.
6+
7+
This constraint is used to ensure that a value has the proper format of a
8+
`Business Identifier Code (BIC)`_. BIC is an internationally agreed means to
9+
uniquely identify both financial and non-financial institutions.
10+
11+
+----------------+-----------------------------------------------------------------------+
12+
| Applies to | :ref:`property or method <validation-property-target>` |
13+
+----------------+-----------------------------------------------------------------------+
14+
| Options | - `message`_ |
15+
| | - `payload`_ |
16+
+----------------+-----------------------------------------------------------------------+
17+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Bic` |
18+
+----------------+-----------------------------------------------------------------------+
19+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\BicValidator` |
20+
+----------------+-----------------------------------------------------------------------+
21+
22+
Basic Usage
23+
-----------
24+
25+
To use the Bic validator, simply apply it to a property on an object that
26+
will contain a Business Identifier Code (BIC).
27+
28+
.. configuration-block::
29+
30+
.. code-block:: php-annotations
31+
32+
// src/AppBundle/Entity/Transaction.php
33+
namespace AppBundle\Entity;
34+
35+
use Symfony\Component\Validator\Constraints as Assert;
36+
37+
class Transaction
38+
{
39+
/**
40+
* @Assert\Bic()
41+
*/
42+
protected $businessIdentifierCode;
43+
}
44+
45+
.. code-block:: yaml
46+
47+
# src/AppBundle/Resources/config/validation.yml
48+
AppBundle\Entity\Transaction:
49+
properties:
50+
businessIdentifierCode:
51+
- Bic:
52+
message: This is not a valid Business Identifier Code (BIC).
53+
54+
.. code-block:: xml
55+
56+
<!-- src/AppBundle/Resources/config/validation.xml -->
57+
<?xml version="1.0" encoding="UTF-8" ?>
58+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
59+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
60+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
61+
62+
<class name="AppBundle\Entity\Transaction">
63+
<property name="businessIdentifierCode">
64+
<constraint name="Bic">
65+
<option name="message">
66+
This is not a valid Business Identifier Code (BIC).
67+
</option>
68+
</constraint>
69+
</property>
70+
</class>
71+
</constraint-mapping>
72+
73+
.. code-block:: php
74+
75+
// src/AppBundle/Entity/Transaction.php
76+
namespace AppBundle\Entity;
77+
78+
use Symfony\Component\Validator\Mapping\ClassMetadata;
79+
use Symfony\Component\Validator\Constraints as Assert;
80+
81+
class Transaction
82+
{
83+
protected $businessIdentifierCode;
84+
85+
public static function loadValidatorMetadata(ClassMetadata $metadata)
86+
{
87+
$metadata->addPropertyConstraint('businessIdentifierCode', new Assert\Bic(array(
88+
'message' => 'This is not a valid Business Identifier Code (BIC).',
89+
)));
90+
}
91+
}
92+
93+
Available Options
94+
-----------------
95+
96+
message
97+
~~~~~~~
98+
99+
**type**: ``string`` **default**: ``This is not a valid Business Identifier Code (BIC).``
100+
101+
The default message supplied when the value does not pass the BIC check.
102+
103+
.. include:: /reference/constraints/_payload-option.rst.inc
104+
105+
.. _`Business Identifier Code (BIC)`: https://en.wikipedia.org/wiki/Business_Identifier_Code

reference/constraints/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ File Constraints
6666
Financial and other Number Constraints
6767
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6868

69+
* :doc:`Bic </reference/constraints/Bic>`
6970
* :doc:`CardScheme </reference/constraints/CardScheme>`
7071
* :doc:`Currency </reference/constraints/Currency>`
7172
* :doc:`Luhn </reference/constraints/Luhn>`

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy