public static function CommercePaymentCreditCard::validateNumber in Commerce Core 7
Validates the given credit card number.
Parameters
string $number: The credit card number.
array $type: The credit card type.
Return value
bool TRUE if the credit card number is valid, FALSE otherwise.
2 calls to CommercePaymentCreditCard::validateNumber()
- CommercePaymentCreditCardTest::testValidateNumber in modules/
payment/ tests/ commerce_payment_credit_card.test - Tests type detection.
- commerce_payment_validate_credit_card_number in modules/
payment/ includes/ commerce_payment.credit_card.inc - Validates a credit card number using the Luhn algorithm.
File
- modules/
payment/ includes/ commerce_payment.credit_card.inc, line 565 - Credit-card helper functions for Drupal commerce.
Class
- CommercePaymentCreditCard
- Provides logic for listing card types and validating card details.
Code
public static function validateNumber($number, array $type) {
if (!is_numeric($number)) {
return FALSE;
}
if (!in_array(strlen($number), $type['number_lengths'])) {
return FALSE;
}
if ($type['uses_luhn'] && !self::validateLuhn($number)) {
return FALSE;
}
return TRUE;
}