Archives
Master Symfony2 fundamentals
Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com
Symfony hosting done right
ServerGrove, outstanding support at the right price for your Symfony hosting needs.
servergrove.com
Discover the SensioLabs Support
Access to the SensioLabs Competency Center for an exclusive and tailor-made support on Symfony
sensiolabs.com
Blog
New in Symfony 2.2: Payment related validators
by
Fabien Potencier
– December 12, 2012
– 13 comments
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:
1 2 3 4 5 6 7 8 9 10 11 | // 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.





is a trademark of Fabien Potencier. All rights reserved.
Add a Comment
Comments