You are here

public static function CreditCard::matchPrefix in Commerce Core 8.2

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 CreditCard::matchPrefix()
CreditCard::detectType in modules/payment/src/CreditCard.php
Detects the credit card type based on the number.

File

modules/payment/src/CreditCard.php, line 156

Class

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

Namespace

Drupal\commerce_payment

Code

public static function matchPrefix(string $number, string $prefix) : bool {
  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;
  }
}