New in Symfony 2.2: Payment related validators

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.

Contributed by
Tim Nagel
in #4734 and #5072.

If you are developing an e-commerce solution based on Symfony2, you might want to validate a credit card number before sending it to your payment gateway. Doing so is very simple in Symfony 2.2 thanks to the Luhn algorithm and its implementation as a validator:

// src/Acme/SubscriptionBundle/Entity/Transaction.php

use Symfony\Component\Validator\Constraints as Assert;

class Transaction
     * @Assert\Luhn(message = "Please check your credit card number.")
    protected $cardNumber;

You can also check the card scheme thanks to Symfony\Component\Validator\Constraints\CardSchemeValidator.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.


that is great
Wow! It's awesome!
Great job! Financial validators was most buggy place when somebody wrote it in project!
Cool. I was using for this.
BTW, it would be nice to notify translators to provide translation for this new message in as many languages as possible.
It's not a Luhn validator, This validator is a number check, php implementation of Luhn algorithm can be found here
good job
@Francis it is the real luhn algorithm, check :
Wow, I'm loving these 'New in SF2' articles - nice way to communicate the changes without me looking for new features in change logs etc.
User may need multi language here.
@Pascal that'll teach me to read the articles too fast, thank you for providing the link
Thumbs up!

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.