Thai Citizen ID validator is a easy-to-use PHP library designed to help validate Thai National Identification Card numbers
You can install the package via composer:
composer require farzai/thai-citizen-id-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
}
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
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],
]);
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.