Search by

x-laravel / validation-tr-citizen-number-extend

X-Adam

Turkey citizen number (TC No) validation extend package for Laravel.

Package info

github.com/x-laravel/validation-tr-citizen-number-extend

pkg:composer/x-laravel/validation-tr-citizen-number-extend

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-09-19 21:27 UTC

This package is auto-updated.

Last update: 2026-09-19 21:36:40 UTC


README

Tests Latest Stable Version PHP Version Total Downloads License

A Laravel validation rule for Turkish citizen numbers (T.C. Kimlik No). It wraps x-adam/tr-citizen-number-validation, which checks the number offline against the official checksum rules — no network access, no dependencies beyond Laravel itself.

Requirements

Package version PHP Laravel
2.x 8.2+ 12, 13
1.x 7.0+ 5.5+

Installation

composer require x-laravel/validation-tr-citizen-number-extend

The service provider is registered through package discovery.

Usage

Rule object

use XLaravel\ValidationTrCitizenNumberExtend\Rules\TrCitizenNumber;

$request->validate([
    'citizen_no' => ['required', new TrCitizenNumber],
]);

The rule object comes with Turkish and English error messages and picks the one matching the application locale.

String alias

$request->validate([
    'citizen_no' => ['required', 'tr_citizen_number'],
]);

For the string alias Laravel resolves the error message the way it does for any extended rule, so add a line to your application's lang/xx/validation.php:

'tr_citizen_number' => ':attribute geçerli bir T.C. kimlik numarası olmalıdır.',

Without it Laravel falls back to the raw key validation.tr_citizen_number. You can also pass an inline message through the validator's messages argument or a form request's messages() method.

Either form accepts int and string values; anything else — arrays, booleans, floats — fails validation instead of throwing.

Customising the messages

To change the rule object's messages, publish the language files and edit them:

php artisan vendor:publish --tag=tr-citizen-number-translations

They land in lang/vendor/tr-citizen-number/{tr,en}/validation.php.

What it checks

The rule answers "is this a well-formed citizen number?" — length, leading digit and both check digits. It does not verify that the number belongs to a particular person; that requires the KPS service of the Turkish Directorate of Population and Citizenship Affairs, which is only available to institutions with a membership.

Testing

composer install
composer test
composer analyse

The suite runs on Orchestra Testbench against every supported Laravel and PHP combination in CI, along with PHPStan (Larastan) at its highest level.

License

Open source software licensed under the MIT license.