You are here

public static function CommercePaymentCreditCard::validateExpirationDate in Commerce Core 7

Validates the given credit card expiration date.

Parameters

string $month: The 1 or 2-digit numeric representation of the month, i.e. 1, 6, 12.

string $year: The 4-digit numeric representation of the year, i.e. 2010.

Return value

bool TRUE if the credit card expiration date is valid, FALSE otherwise.

2 calls to CommercePaymentCreditCard::validateExpirationDate()
CommercePaymentCreditCardTest::testValidateExpirationDate in modules/payment/tests/commerce_payment_credit_card.test
Tests expiration date validation.
commerce_payment_validate_credit_card_exp_date in modules/payment/includes/commerce_payment.credit_card.inc
Validates a credit card expiration date.

File

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

Class

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

Code

public static function validateExpirationDate($month, $year) {
  if ($month < 1 || $month > 12) {
    return FALSE;
  }
  if ($year < date('Y')) {
    return FALSE;
  }
  elseif ($year == date('Y') && $month < date('n')) {
    return FALSE;
  }
  return TRUE;
}