Search by

x-adam / tr-tax-number-validation

X-Adam

Turkey tax number validation class.

Package info

github.com/X-Adam/tr-tax-number-validation

Issues

pkg:composer/x-adam/tr-tax-number-validation

Statistics

Installs: 906

Dependents: 2

Suggesters: 0

Stars: 0

v5.0.0 2026-09-19 21:50 UTC

This package is auto-updated.

Last update: 2026-09-19 21:58:11 UTC


README

Tests Latest Stable Version PHP Version Total Downloads License

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

composer require x-adam/tr-tax-number-validation

Usage

use XAdam\TrTaxNumberValidation;

TrTaxNumberValidation::validate(3973535717);   // true
TrTaxNumberValidation::validate('3973535717'); // true
TrTaxNumberValidation::validate('1234567891'); // false

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:

TrTaxNumberValidation::validate('not a number'); // false
TrTaxNumberValidation::validate('');             // false
TrTaxNumberValidation::validate('397353571');    // false (9 digits)

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

composer install
composer test
composer analyse

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.