antalaron/vat-number-validator

PHP library to validate VAT numbers

Maintainers

πŸ‘ antalaron

Package info

github.com/antalaron/vat-number-validator

pkg:composer/antalaron/vat-number-validator

Statistics

Installs: 72 845

Dependents: 2

Suggesters: 0

Stars: 6

Open Issues: 3

v1.2.1 2025-03-19 12:32 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

Replaces

None

MIT 7be59d8d9b770f069be217031ac57926dc001dda

  • Antal Áron <antalaron.woop@antalaron.hu>

This package is auto-updated.

Last update: 2026-06-20 13:27:23 UTC


README

πŸ‘ Build Status
πŸ‘ Coverage Status
πŸ‘ Latest Stable Version
πŸ‘ Latest Unstable Version
πŸ‘ License

PHP library to validate VAT numbers.

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this library:

$ composer require antalaron/vat-number-validator

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Basic usage

To validate a VAT number:

use Antalaron\Component\VatNumberValidator\VatNumber;
use Symfony\Component\Validator\Validation;

$validator = Validation::createValidator();
$violations = $validator->validate('ATU37675002', new VatNumber());

if (0 !== count($violations)) {
 foreach ($violations as $violation) {
 echo $violation->getMessage().'<br>';
 }
}

You can add your own VAT validator via extraVat option:

$violations = $validator->validate('11', new VatNumber(['extraVat' => function ($number) {
 return 0 !== preg_match('/^(\d{2})$/', $number);
}]));

Origin

This library is the PHP rewrite of original JavaScript library by Braemoor Software Freebies. Original contributors are found here.

License

This library is under MIT License.