You are here

public static function CommercePaymentCreditCard::matchPrefix in Commerce Core 7

Checks whether the given credit card number matches the given prefix.

Parameters

string $number: The credit card number.

string $prefix: The prefix to match against. Can be a single number such as '43' or a range such as '30-35'.

Return value

bool TRUE if the credit card number matches the prefix, FALSE otherwise.

1 call to CommercePaymentCreditCard::matchPrefix()
CommercePaymentCreditCard::detectType in modules/payment/includes/commerce_payment.credit_card.inc
Detects the credit card type based on the number.

File

modules/payment/includes/commerce_payment.credit_card.inc, line 543
Credit-card helper functions for Drupal commerce.

Class

CommercePaymentCreditCard
Provides logic for listing card types and validating card details.

Code

public static function matchPrefix($number, $prefix) {
  if (is_numeric($prefix)) {
    return substr($number, 0, strlen($prefix)) == $prefix;
  }
  else {
    list($start, $end) = explode('-', $prefix);
    $number = substr($number, 0, strlen($start));
    return $number >= $start && $number <= $end;
  }
}