PHPackages                             yhdleung/hkid-util - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. yhdleung/hkid-util

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yhdleung/hkid-util
==================

Utility functions for tasks related to Hong Kong Identity Card (HKID)

1.0.1(4y ago)160MITPHPPHP &gt;=5.3.0

Since Mar 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/yhdleung/HKIDUtil)[ Packagist](https://packagist.org/packages/yhdleung/hkid-util)[ Docs](https://github.com/yhdleung/HKIDUtil)[ RSS](/packages/yhdleung-hkid-util/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

HKIDUtil
========

[](#hkidutil)

PHP Utility functions designed to help tasks related to Hong Kong Identity Card (HKID).

[![Latest Stable Version](https://camo.githubusercontent.com/5c5655a1c6458caf02cc837b6cbb2125edd7f80360262403202db47fc498f746/68747470733a2f2f706f7365722e707567782e6f72672f7968646c65756e672f686b69642d7574696c2f762f737461626c65)](https://packagist.org/packages/yhdleung/hkid-util)[![License](https://camo.githubusercontent.com/25d06c0acae0e40bf9124ecf6777ad0597b8b45d664aeeadf66746a2ede8632f/68747470733a2f2f706f7365722e707567782e6f72672f7968646c65756e672f686b69642d7574696c2f6c6963656e7365)](https://packagist.org/packages/yhdleung/hkid-util)

Features
--------

[](#features)

- Support two-letter prefix (e.g. AB987654(3))
- For HKID input, parentheses are optional

Requirement
-----------

[](#requirement)

- PHP 5.3+

Functions
---------

[](#functions)

- getCheckDigit - Get the Check Digit of HKID

```
char HKIDUtil::getCheckDigit(string $id)

```

- validateHKID - Validate HKID format

```
bool HKIDUtil::validateHKID(string $id)

```

- randomHKID - Generate random HKID

```
string HKIDUtil::randomHKID(bool $hasParentheses=true)

```

- validateDate - Validate date format in 'dd-mm-yyyy' or 'dd/mm/yyyy'

```
bool HKIDUtil::validateDate(string $date)

```

Installation
------------

[](#installation)

Include the utility function file

```
require_once("HKIDUtil.php");
```

Usage
-----

[](#usage)

Get the Check Digit of a HKID

```
$testID = 'C123456';
echo(HKIDUtil::getCheckDigit($testID));  // returns '9'
```

Validate HKID format, check digit parentheses are optional

```
var_dump(HKIDUtil::validateHKID('AB987654(3)'));   // bool(true)

if(HKIDUtil::validateHKID('AB9876543')){
    echo 'valid';
}     //returns 'valid'
```

Generate random HKID

```
echo(HKIDUtil::randomHKID());     // returns HKID, e.g. 'LA654668(9)'

for($i = 0; $i < 3; $i++){
    echo(HKIDUtil::randomHKID(0)) . PHP_EOL;
}
// returns HKID without parentheses, e.g.
// 'Q2127047'
// 'J9009792'
// 'BA1196657'
```

Validate date format in 'dd-mm-yyyy' or 'dd/mm/yyyy'

```
var_dump(HKIDUtil::validateDate('31-12-1969'));     // bool(true)
var_dump(HKIDUtil::validateDate('01/01/1970'));     // bool(true)
var_dump(HKIDUtil::validateDate('1/1/1970'));       // bool(true)
var_dump(HKIDUtil::validateDate('30/02/1970'));     // bool(false)
```

License
-------

[](#license)

See the LICENSE file for license rights and limitations (MIT).

Reference
---------

[](#reference)

This HKID validation formula is developed based on the information from Wikipedia.
[維基百科, 香港身份證 (Wikipedia, Hong Kong Identity Card)](https://zh.wikipedia.org/w/index.php?title=%E9%A6%99%E6%B8%AF%E8%BA%AB%E4%BB%BD%E8%AD%89&variant=zh-hk#.E6.A0.A1.E9.A9.97.E7.A2.BC)

Contribution
------------

[](#contribution)

Star, fork, pull request and issue report are all welcome.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1855 days

Total

2

Last Release

1495d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c1861ae9edf087dcd743e6eb9876057878135061e2f643c91b6d2dd86d594e8?d=identicon)[yhdleung](/maintainers/yhdleung)

---

Top Contributors

[![yhdleung](https://avatars.githubusercontent.com/u/946248?v=4)](https://github.com/yhdleung "yhdleung (14 commits)")

---

Tags

HKIDHong KongHong Kong identity card

### Embed Badge

![Health badge](/badges/yhdleung-hkid-util/health.svg)

```
[![Health](https://phpackages.com/badges/yhdleung-hkid-util/health.svg)](https://phpackages.com/packages/yhdleung-hkid-util)
```

###  Alternatives

[stevenmaguire/zurb-foundation-laravel

Build HTML form elements for Foundation inside Laravel

203.8k](/packages/stevenmaguire-zurb-foundation-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
