farzai / thai-citizen-id-validation
Thai citizen id validation
Fund package maintenance!
parsilver
Requires
- php: ^8.1
Requires (Dev)
- illuminate/contracts: ^8.0|^9.0|^10.0|^11.0
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-laravel: ^1.0|^2.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- spatie/ray: ^1.28
- symfony/var-dumper: ^6.0
README
Thai Citizen ID validator is a easy-to-use PHP library designed to help validate Thai National Identification Card numbers
Installation
You can install the package via composer:
composer require farzai/thai-citizen-id-validation
Usage for validation
Example usage for validating Thai Citizen ID
use Farzai\ThaiIdValidation\Validator; use Farzai\ThaiIdValidation\Exceptions\InvalidThaiCitizenIdException; $validator = new Validator(); try { $validator->validate('1410100100000'); } catch (InvalidThaiCitizenIdException $e) { // Handle invalid citizen id }
Usage for generating
Sometimes you need to generate a random Thai Citizen ID for testing purpose. This library can help you with that.
use Farzai\ThaiIdValidation\Generator; $generator = new Generator(); // Optional $generator ->personType(1) // ประเภทบุคคล ->provinceOfBirth('10') // เลขจังหวัดที่เกิด ->districtOfBirth('10'); // เลขอำเภอที่เกิด // Generate $idCard = $generator->generate(); echo (string)$idCard; // 1410100100000 echo $idCard->getId(); // 1410100100000 echo $idCard->getType(); // 1 digit echo $idCard->getProvinceOfBirth(); // 2 digit echo $idCard->getDistrictOfBirth(); // 2 digit echo $idCard->getVolume(); // 5 digit echo $idCard->getNumber(); // 2 digit echo $idCard->getCheckDigit(); // 1 digit
Usage with Laravel
You can use the IdCard
rule to validate Thai Citizen ID in Laravel.
use Farzai\ThaiIdValidation\Laravel\Rules\IdCard; $request->validate([ 'id_card' => ['required', new IdCard], ]);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.