You are here

public function EuropeanUnionVat::validate in Commerce Core 8.2

Validates the given tax number.

Parameters

string $tax_number: The tax number.

Return value

bool TRUE if the given tax number if valid, FALSE otherwise.

Overrides TaxNumberTypeInterface::validate

File

modules/tax/src/Plugin/Commerce/TaxNumberType/EuropeanUnionVat.php, line 35

Class

EuropeanUnionVat
Provides the European Union VAT tax number type.

Namespace

Drupal\commerce_tax\Plugin\Commerce\TaxNumberType

Code

public function validate($tax_number) {
  $patterns = $this
    ->getValidationPatterns();
  $prefix = substr($tax_number, 0, 2);
  if (!isset($patterns[$prefix])) {
    return FALSE;
  }
  $number = substr($tax_number, 2);
  if (!preg_match('/^' . $patterns[$prefix] . '$/', $number)) {
    return FALSE;
  }
  return TRUE;
}