php artisan aura:add vat-field
Copies the component source into resources/views/components/aura/. Run php artisan aura:init first if you haven't already. See the CLI guide for all options.
composer require bluestarsystem/aura-ui
php artisan aura:install
Full installation instructions in the Installation guide.
Pro Component — This component requires an Aura UI Pro license.
Overview
<x-aura::vat-field> checks a European VAT number, or an Italian codice fiscale, while it is
being typed — by arithmetic, not by asking a server.
A partita IVA carries a check digit computed over its first ten; a codice fiscale a check letter computed over its first fifteen, with a different table for odd and even positions so that swapping two adjacent characters changes the result. Both catch the typo that would otherwise reach an invoice and come back weeks later as a rejected e-invoice.
Basic Usage
The check digit is verified as you type. Whether the business exists is a VIES lookup, not this. That is not a valid VAT number — the check digit does not agree.
<x-aura::vat-field label="VAT number" />Try 00743110157 — valid. Change the last digit and the hint becomes an error.
Fiscal code
Sixteen characters. The final letter is computed from the other fifteen. That is not a valid fiscal code — the final letter does not agree.
<x-aura::vat-field label="Fiscal code" mode="fiscal-code" />RSSMRA80A01H501U is the canonical example. Homocodes — where a digit is replaced by a letter to
separate two people who would otherwise share a code — are accepted.
Validate on the server
use BlueStarSystem\AuraUIPro\Rules\VatNumber;
use BlueStarSystem\AuraUIPro\Rules\FiscalCode;
$request->validate([
'vat_number' => ['required', new VatNumber], // assumes IT when there is no prefix
'fiscal_code' => ['nullable', new FiscalCode],
]);
Support\VatNumber and Support\FiscalCode are the same arithmetic without the validator:
isValid(), normalise(), split(), countries().
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string|null |
null |
Tied to the field with for. |
name |
string |
'vat_number' |
The hidden field's name; posts without spaces or punctuation. |
value |
string|null |
null |
|
country |
string |
'IT' |
Which country's rules apply when the number carries no prefix. |
mode |
string |
'vat' |
vat or fiscal-code. |
hint, error |
string|null |
null |
Description and error text. |
Countries
The Italian check digit is verified in full. For every other country the shape is checked —
length and character classes, which is all that can be done offline. VatNumber::countries()
lists the 27 covered.
What it cannot tell you
Whether the business exists, is active, or is registered for cross-border trade. That is a VIES lookup: a network call, and the wrong thing to do on every keystroke. Check it when you need to know — at invoice time — not while someone is typing.