CoolCMS API

TaxIdHelper
in package

FinalYes

Keeps the shape of company registration and VAT ids in one place.

The length is guarded by ColumnLimits against the column the value is written to (checkout measures the invoice column, where the value ends up on the tax document); this helper guards the shape.

NOTE: the pattern is deliberately loose, not "8 digits" or "CZ + 8-10 digits". The e-shop sells abroad and a strict mask would reject valid foreign VAT ids. The gate only filters nonsense (leading whitespace, control characters, injected HTML) and keeps the length; checking the VAT payer register is a different thing this class does not replace.

Table of Contents

Constants

PATTERN  : string = '[A-Za-z0-9][A-Za-z0-9 ./-]*'
Mask for `Form::PATTERN`; Nette wraps it in `^(?:...)$` itself, hence no anchors here.

Methods

hasValidShape()  : bool
Runs the same check Nette does over the pattern constant, anchored, with modifiers `Du`.
prefixMatchesCountry()  : bool|null
Returns whether the VAT id prefix belongs to the country (flag `VAT_ID_COUNTRY_MISMATCH`).
splitVatId()  : array{prefix: string|null, number: string}|null
Splits a VAT id into the country prefix and the number: separators are dropped, letters upper-cased; two leading letters are the prefix (`CZ12345678` → `CZ` + `12345678`, `ATU12345678` → `AT` + `U12345678`, Greece `EL…`).

Constants

PATTERN

Mask for `Form::PATTERN`; Nette wraps it in `^(?:...)$` itself, hence no anchors here.

public string PATTERN = '[A-Za-z0-9][A-Za-z0-9 ./-]*'

Starts with a letter or digit (not a separator) and may continue with alphanumerics and the separators that occur in foreign identifiers.

Methods

hasValidShape()

Runs the same check Nette does over the pattern constant, anchored, with modifiers `Du`.

public static hasValidShape(string|null $value) : bool

An empty value passes; setRequired() handles presence, not the shape.

Parameters
$value : string|null
Return values
bool

prefixMatchesCountry()

Returns whether the VAT id prefix belongs to the country (flag `VAT_ID_COUNTRY_MISMATCH`).

public static prefixMatchesCountry(string|null $vatId, string $countryVatPrefix) : bool|null

Compares with the VAT prefix of the country, not its ISO code (Greece is ISO GR, prefix EL).

Parameters
$vatId : string|null
$countryVatPrefix : string

cms_system_countries.vat_prefix of the address country

Return values
bool|null —

null = nothing to compare (no usable VAT id or no letter prefix)

splitVatId()

Splits a VAT id into the country prefix and the number: separators are dropped, letters upper-cased; two leading letters are the prefix (`CZ12345678` → `CZ` + `12345678`, `ATU12345678` → `AT` + `U12345678`, Greece `EL…`).

public static splitVatId(string|null $value) : array{prefix: string|null, number: string}|null

No leading letter pair → prefix = null (the caller falls back to the address country).

Parameters
$value : string|null
Return values
array{prefix: string|null, number: string}|null —

null = nothing usable

On this page

Search results