Skip to content

ตรวจสอบเลขบัตรประชาชน และสุ่มเลขบัตร

License

Notifications You must be signed in to change notification settings

farzai/thai-citizen-id-validation-php

Repository files navigation

Thai Citizen ID Validator PHP

Latest Version on Packagist Tests codecov Total Downloads

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.

About

ตรวจสอบเลขบัตรประชาชน และสุ่มเลขบัตร

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages