https://github.com/tox82/vatnumbervalidator
A simple, no dependency formal VAT number validator
https://github.com/tox82/vatnumbervalidator
Last synced: about 1 year ago
JSON representation
A simple, no dependency formal VAT number validator
- Host: GitHub
- URL: https://github.com/tox82/vatnumbervalidator
- Owner: ToX82
- License: gpl-3.0
- Created: 2022-01-15T14:29:02.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-31T13:13:16.000Z (almost 3 years ago)
- Last Synced: 2025-02-04T21:19:08.235Z (over 1 year ago)
- Language: PHP
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VAT validator
## A formal VAT number validator
It's not a full validation tool, it just checks that the VAT number is formally valid: eg. 11 chars, digits only, etc.
It's built using these rules:
* https://www.gov.uk/guidance/vat-eu-country-codes-vat-numbers-and-vat-in-other-languages
* https://en.wikipedia.org/wiki/VAT_identification_number
It requires PHP >= 7.0.
Installation:
```shell
composer require tox82/vatnumber-validator
```
Usage
-----------
Just load the VatNumber class and execute a check, passing the country code and VAT code as parameters,
and it will return a boolean value. True for valid VAT number, false for invalid.
```php
use Tox82\VatNumber;
...
echo VatNumber::check('FR', '12345678901'); // true
echo VatNumber::check('HU', '12345678'); // true
echo VatNumber::check('PT', '123456789'); // true
echo VatNumber::check('SE', '123456789012'); // true
echo VatNumber::check('AT', 'U123456780'); // false because of invalid number's length
echo VatNumber::check('MK', 'AA4032013544513'); // false because of invalid characters
```
TODO
-----------
Add specific, more robust validation for each country, when available. Eg. check digits. prefixes, suffixes, etc.
Resources
---------
* [Report issues](https://github.com/ToX82/VatNumberValidator/issues)
* [Send Pull Requests](https://github.com/ToX82/VatNumberValidator/pulls)
* [Check the main repository](https://github.com/ToX82/VatNumberValidator)