Download the PHP package x-adam/tr-tax-number-validation without Composer
On this page you can find all versions of the php package x-adam/tr-tax-number-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download x-adam/tr-tax-number-validation
More information about x-adam/tr-tax-number-validation
Files in x-adam/tr-tax-number-validation
Package tr-tax-number-validation
Short Description Turkey tax number validation class.
License MIT
Informations about the package tr-tax-number-validation
Turkish Tax Number Validation
Offline validation for Turkish tax identification numbers (Vergi Kimlik No). Zero dependencies, a single static method, and no network access — the number is checked against the official checksum rule.
Requirements
PHP 8.1 or higher. Nothing else.
Installation
Usage
Both int and string are accepted, so values coming straight from a request need no casting or
pre-filtering. Anything that is not a well-formed tax number — letters, empty strings, surrounding
whitespace, wrong length — returns false instead of throwing:
What it checks
A Turkish tax number is 10 digits long; the last one is a check digit computed from the first nine.
For each of the first nine digits d at position p (counted from 9 down to 1):
| Step | Formula |
|---|---|
| Intermediate | m = (d + p) mod 10 |
| Weighted | w = (m × 2^p) mod 9, except w = 9 when m = 9 |
| Check digit | (10 − Σw mod 10) mod 10 |
The library returns true only when the computed check digit equals the tenth digit.
What it does not check
This library answers "is this a well-formed tax number?", not "is this number registered to this taxpayer?". The latter requires querying the Revenue Administration (GİB), which is outside the scope of an offline checksum.
Use this library to reject malformed input early — before storing it, or before paying for a lookup.
Laravel
For a ready-made tr_tax_number validation rule, see
x-laravel/validation-tr-tax-number-extend,
which wraps this library.
Testing
The suite covers the documented rule, malformed input, generated valid numbers, and every combination of positions whose intermediate value is nine. CI runs it on PHP 8.1 through 8.5, along with PHPStan at its highest level.
License
Open source software licensed under the MIT license.