You are here

function _vat_number_components in VAT Number 7

Splitting up a VAT to country prefix and number and clean it from spaces etc.

2 calls to _vat_number_components()
_vat_number_check_vat_format in ./vat_number.inc
Pre check, to output good error messages that can help the user.
_vat_number_validate_vat in ./vat_number.inc
Check a VAT number. Return error message on error, FALSE on success.

File

./vat_number.inc, line 478
vat_number.inc

Code

function _vat_number_components($vat_number) {

  // 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('/[ .-]/', '', $vat_number);

  // First two letters are always country code.
  $vat_infos['country_code'] = drupal_strtoupper(drupal_substr($vatid, 0, 2));
  $vat_infos['vat_number'] = drupal_strtoupper(drupal_substr($vatid, 2));
  return $vat_infos;
}