Skip to content

Commit 0b72af9

Browse files
committed
Merge pull request symfony#2522 from sprain/LuhnValidator
Improved Luhn validator doc
2 parents b9b3165 + e6d6532 commit 0b72af9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

reference/constraints/Luhn.rst

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Luhn
2-
======
2+
====
33

44
.. versionadded:: 2.2
55
The Luhn validation is new in Symfony 2.2.
@@ -49,6 +49,8 @@ will contain a credit card number.
4949
.. code-block:: php-annotations
5050
5151
// src/Acme/SubscriptionBundle/Entity/Transaction.php
52+
namespace Acme\SubscriptionBundle\Entity\Transaction;
53+
5254
use Symfony\Component\Validator\Constraints as Assert;
5355
5456
class Transaction
@@ -62,16 +64,18 @@ will contain a credit card number.
6264
.. code-block:: php
6365
6466
// src/Acme/SubscriptionBundle/Entity/Transaction.php
67+
namespace Acme\SubscriptionBundle\Entity\Transaction;
68+
6569
use Symfony\Component\Validator\Mapping\ClassMetadata;
66-
use Symfony\Component\Validator\Constraints\Luhn;
70+
use Symfony\Component\Validator\Constraints as Assert;
6771
6872
class Transaction
6973
{
7074
protected $cardNumber;
7175
7276
public static function loadValidatorMetadata(ClassMetadata $metadata)
7377
{
74-
$metadata->addPropertyConstraint('luhn', new Luhn(array(
78+
$metadata->addPropertyConstraint('cardNumber', new Assert\Luhn(array(
7579
'message' => 'Please check your credit card number',
7680
)));
7781
}
@@ -87,4 +91,4 @@ message
8791

8892
The default message supplied when the value does not pass the Luhn check.
8993

90-
.. _`Luhn algorithm`: http://en.wikipedia.org/wiki/Luhn_algorithm
94+
.. _`Luhn algorithm`: http://en.wikipedia.org/wiki/Luhn_algorithm

0 commit comments

Comments
 (0)