lizhineng/vehicle-license-china

Vehicle license library for China.

v0.1.0 2025-05-14 06:20 UTC

This package is auto-updated.

Last update: 2025-05-14 06:25:44 UTC


README

MIT License Tests Downloads

The library implements the GA 36-2018, which helps you validate the vehicle registration number issued in mainland China and extract the information from the plate number.

Install

The package can be installed through Composer and requires PHP 8.4+

composer require lizhineng/vehicle-license-china

Usage

You can easily create an instance of a registration number with the make factory method. All validation will be checked against the plate number before initialization; otherwise, a RegistrationNumberException will be thrown.

use Zhineng\VehicleLicenseChina\RegistrationNumber;
use Zhineng\VehicleLicenseChina\RegistrationNumberException;

try {
    $registrationNumber = RegistrationNumber::make('粤E12345');
} catch (RegistrationNumberException $e) {
    // The registration number is invalid.
}

The library supports all vehicle types defined in the standard: embassy, consulate, police, coach, trailer, Hong Kong, Macau, test, and special vehicles.

$registrationNumber->isEmbassy();
$registrationNumber->isConsulate();
$registrationNumber->isPolice();
$registrationNumber->isCoach();
$registrationNumber->isTrailer();
$registrationNumber->isFromHongKong();
$registrationNumber->isFromMacau();
$registrationNumber->isTest();
$registrationNumber->isSpecial();

To differentiate clean energy vehicles, note that these plate numbers apply only to those without any suffix.

$registrationNumber->isCleanEnergy();

// Check if it's a small clean energy vehicle
$registrationNumber->isSmallCleanEnergy();

// Check if it's a large clean energy vehicle
$registrationNumber->isLargeCleanEnergy();

You can further specify if a clean energy vehicle is entirely powered by electricity.

$registrationNumber->isBatteryElectric();

License

The library is licensed under the MIT license.