Backend Development 3 min read

PHP Composer ID Validator: Features, Installation, Usage, and Information Retrieval

This article introduces the PHP Composer package "jxlwqq/id-validator", detailing its capabilities to validate Chinese resident ID numbers, upgrade 15‑digit IDs to 18‑digit, generate synthetic IDs, retrieve detailed personal information, and explains installation, usage examples, and the structure of the returned data.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP Composer ID Validator: Features, Installation, Usage, and Information Retrieval

1. Features

Validate mainland China resident ID numbers

Retrieve detailed ID information (region, birthdate, zodiac, gender, checksum)

Upgrade 15‑digit IDs to 18‑digit format

Generate synthetically valid IDs

2. Installation

composer require "jxlwqq/id-validator"

3. Basic Usage – Validation

<?php
use Jxlwqq\IdValidator\IdValidator;
$idValidator = new IdValidator();
// Mainland 18‑digit ID
$isValid = $idValidator->isValid('440308199901101512');
// Mainland 15‑digit ID
$isValid15 = $idValidator->isValid('810000199408230021');
// Hong Kong/Macau/Taiwan residence permit (18‑digit)
$isValidHK = $idValidator->isValid('830000199201300022');
?>

4. Retrieve ID Information

<?php
use Jxlwqq\IdValidator\IdValidator;
$idValidator = new IdValidator();
$info = $idValidator->getInfo('440308199901101512');
?>

The $info array contains keys such as:

[
    'addressCode'   => '440308',          // address code
    'abandoned'     => 0,                // whether the address code is obsolete
    'address'       => '广东省深圳市盐田区', // full address string
    'addressTree'   => ['广东省','深圳市','盐田区'],
    'birthdayCode' => '1999-01-10',
    'constellation'=> '水瓶座',
    'chineseZodiac'=> '卯兔',
    'sex'          => 1,                // 1 = male, 0 = female
    'length'        => 18,
    'checkBit'      => '2'
]
?>

5. Notes

The determination of whether an address code is abandoned relies on the historical administrative division code dataset released annually by the Ministry of Civil Affairs of the People’s Republic of China. The dataset is provided in CSV format for easy analysis or porting to other languages.

6. Open‑source Repository

GitHub: https://github.com/jxlwqq/id-validator

Backendvalidationopen-sourcePHPComposerchina-idid-validator
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.