You are here

private function VatNumberController::getComponents in VAT Number 8

Splits a VAT identification number to a clean country prefix and number.

1 call to VatNumberController::getComponents()
VatNumberController::__construct in src/Controller/VatNumberController.php

File

src/Controller/VatNumberController.php, line 70

Class

VatNumberController
Defines a controller to validate the VAT Number.

Namespace

Drupal\vat_number\Controller

Code

private function getComponents() {

  // Some countries like DK use spaces in the formatting.
  // Maybe someone does that too for readability or uses dots.
  // We remove all dots, spaces and dashes because they are not
  // important for the validation operations and we do NOT regex spaces.
  $vatid = preg_replace('/[ .-]/', '', $this->vatNumber);

  // First two letters are always country code.
  $vat_infos['country_code'] = Unicode::strtoupper(Unicode::substr($vatid, 0, 2));
  $vat_infos['vatNumber'] = Unicode::strtoupper(Unicode::substr($vatid, 2));
  return $vat_infos;
}