LuhnValidator

class LuhnValidator extends ConstraintValidator

Validates a PAN using the LUHN Algorithm.

For a list of example card numbers that are used to test this class, please see the LuhnValidatorTest class.

Constants

PRETTY_DATE

Whether to format {@link \DateTime} objects as RFC-3339 dates ("Y-m-d H:i:s").

OBJECT_TO_STRING

Whether to cast objects with a "__toString()" method to strings.

Methods

initialize(ExecutionContextInterface $context)

Initializes the constraint validator.

from ConstraintValidator
validate(mixed $value, Constraint $constraint)

Validates a credit card number with the Luhn algorithm.

Details

initialize(ExecutionContextInterface $context)

Initializes the constraint validator.

Parameters

ExecutionContextInterface $context The current validation context

validate(mixed $value, Constraint $constraint)

Validates a credit card number with the Luhn algorithm.

Parameters

mixed $value The value that should be validated
Constraint $constraint The constraint for the validation

Exceptions

UnexpectedTypeException when the given credit card number is no string

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/4.0/Symfony/Component/Validator/Constraints/LuhnValidator.html