CardSchemeValidator
extends ConstraintValidator
in package
Validates that a card number belongs to a specified scheme.
Tags
Table of Contents
Constants
- OBJECT_TO_STRING = 2
- Whether to cast objects with a "__toString()" method to strings.
- PRETTY_DATE = 1
- Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter} (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s").
Properties
- $context : ExecutionContextInterface
- $schemes : mixed
Methods
- initialize() : mixed
- Initializes the constraint validator.
- validate() : mixed
- Validates a creditcard belongs to a specified scheme.
- formatTypeOf() : string
- Returns a string representation of the type of the value.
- formatValue() : string
- Returns a string representation of the value.
- formatValues() : string
- Returns a string representation of a list of values.
Constants
OBJECT_TO_STRING
Whether to cast objects with a "__toString()" method to strings.
public
mixed
OBJECT_TO_STRING
= 2
PRETTY_DATE
Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter} (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s").
public
mixed
PRETTY_DATE
= 1
Properties
$context
protected
ExecutionContextInterface
$context
$schemes
protected
mixed
$schemes
= [
// American Express card numbers start with 34 or 37 and have 15 digits.
\Symfony\Component\Validator\Constraints\CardScheme::AMEX => ['/^3[47][0-9]{13}$/'],
// China UnionPay cards start with 62 and have between 16 and 19 digits.
// Please note that these cards do not follow Luhn Algorithm as a checksum.
\Symfony\Component\Validator\Constraints\CardScheme::CHINA_UNIONPAY => ['/^62[0-9]{14,17}$/'],
// Diners Club card numbers begin with 300 through 305, 36 or 38. All have 14 digits.
// There are Diners Club cards that begin with 5 and have 16 digits.
// These are a joint venture between Diners Club and MasterCard, and should be processed like a MasterCard.
\Symfony\Component\Validator\Constraints\CardScheme::DINERS => ['/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/'],
// Discover card numbers begin with 6011, 622126 through 622925, 644 through 649 or 65.
// All have 16 digits.
\Symfony\Component\Validator\Constraints\CardScheme::DISCOVER => ['/^6011[0-9]{12}$/', '/^64[4-9][0-9]{13}$/', '/^65[0-9]{14}$/', '/^622(12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|91[0-9]|92[0-5])[0-9]{10}$/'],
// InstaPayment cards begin with 637 through 639 and have 16 digits.
\Symfony\Component\Validator\Constraints\CardScheme::INSTAPAYMENT => ['/^63[7-9][0-9]{13}$/'],
// JCB cards beginning with 2131 or 1800 have 15 digits.
// JCB cards beginning with 35 have 16 digits.
\Symfony\Component\Validator\Constraints\CardScheme::JCB => ['/^(?:2131|1800|35[0-9]{3})[0-9]{11}$/'],
// Laser cards begin with either 6304, 6706, 6709 or 6771 and have between 16 and 19 digits.
\Symfony\Component\Validator\Constraints\CardScheme::LASER => ['/^(6304|670[69]|6771)[0-9]{12,15}$/'],
// Maestro international cards begin with 675900..675999 and have between 12 and 19 digits.
// Maestro UK cards begin with either 500000..509999 or 560000..699999 and have between 12 and 19 digits.
\Symfony\Component\Validator\Constraints\CardScheme::MAESTRO => ['/^(6759[0-9]{2})[0-9]{6,13}$/', '/^(50[0-9]{4})[0-9]{6,13}$/', '/^5[6-9][0-9]{10,17}$/', '/^6[0-9]{11,18}$/'],
// All MasterCard numbers start with the numbers 51 through 55. All have 16 digits.
// October 2016 MasterCard numbers can also start with 222100 through 272099.
\Symfony\Component\Validator\Constraints\CardScheme::MASTERCARD => ['/^5[1-5][0-9]{14}$/', '/^2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12})$/'],
// Payment system MIR numbers start with 220, then 1 digit from 0 to 4, then between 12 and 15 digits
\Symfony\Component\Validator\Constraints\CardScheme::MIR => ['/^220[0-4][0-9]{12,15}$/'],
// All UATP card numbers start with a 1 and have a length of 15 digits.
\Symfony\Component\Validator\Constraints\CardScheme::UATP => ['/^1[0-9]{14}$/'],
// All Visa card numbers start with a 4 and have a length of 13, 16, or 19 digits.
\Symfony\Component\Validator\Constraints\CardScheme::VISA => ['/^4([0-9]{12}|[0-9]{15}|[0-9]{18})$/'],
]
Methods
initialize()
Initializes the constraint validator.
public
initialize(ExecutionContextInterface $context) : mixed
Parameters
- $context : ExecutionContextInterface
validate()
Validates a creditcard belongs to a specified scheme.
public
validate(mixed $value, Constraint $constraint) : mixed
Parameters
- $value : mixed
- $constraint : Constraint
formatTypeOf()
Returns a string representation of the type of the value.
protected
formatTypeOf(mixed $value) : string
This method should be used if you pass the type of a value as message parameter to a constraint violation. Note that such parameters should usually not be included in messages aimed at non-technical people.
Parameters
- $value : mixed
Return values
stringformatValue()
Returns a string representation of the value.
protected
formatValue(mixed $value[, int $format = 0 ]) : string
This method returns the equivalent PHP tokens for most scalar types (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped in double quotes ("). Objects, arrays and resources are formatted as "object", "array" and "resource". If the $format bitmask contains the PRETTY_DATE bit, then objects will be formatted with the . If it is not available, they will be formatted as RFC-3339 dates ("Y-m-d H:i:s").
Be careful when passing message parameters to a constraint violation that (may) contain objects, arrays or resources. These parameters should only be displayed for technical users. Non-technical users won't know what an "object", "array" or "resource" is and will be confused by the violation message.
Parameters
- $value : mixed
- $format : int = 0
-
A bitwise combination of the format constants in this class
Return values
stringformatValues()
Returns a string representation of a list of values.
protected
formatValues(array<string|int, mixed> $values[, int $format = 0 ]) : string
Each of the values is converted to a string using . The values are then concatenated with commas.
Parameters
- $values : array<string|int, mixed>
-
A list of values
- $format : int = 0
-
A bitwise combination of the format constants in this class