PHPackages                             ilexn/hkid-check-digit - 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. ilexn/hkid-check-digit

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

ilexn/hkid-check-digit
======================

HKID digit check

6.1.0(3mo ago)21.5k↓25%1MITPHPPHP &gt;=8.4CI passing

Since Dec 15Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/iLexN/HKID-Check-Digit)[ Packagist](https://packagist.org/packages/ilexn/hkid-check-digit)[ GitHub Sponsors](https://github.com/iLexN)[ RSS](/packages/ilexn-hkid-check-digit/feed)WikiDiscussions 6.x Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (32)Used By (0)

Validation of HKID
==================

[](#validation-of-hkid)

> Used to validation the format and check digit calculation for HKID.

```
 __    __   __  ___  __   _______       ______  __    __   _______   ______  __  ___
|  |  |  | |  |/  / |  | |       \     /      ||  |  |  | |   ____| /      ||  |/  /
|  |__|  | |  '  /  |  | |  .--.  |   |  ,----'|  |__|  | |  |__   |  ,----'|  '  /
|   __   | |    <   |  | |  |  |  |   |  |     |   __   | |   __|  |  |     |    <
|  |  |  | |  .  \  |  | |  '--'  |   |  `----.|  |  |  | |  |____ |  `----.|  .  \
|__|  |__| |__|\__\ |__| |_______/     \______||__|  |__| |_______| \______||__|\__\

```

[![Latest Stable Version](https://camo.githubusercontent.com/3ffb449c62471eb1385dda0bb073d0725fc6daaf26ec0708066817ad253fac41/68747470733a2f2f706f7365722e707567782e6f72672f696c65786e2f686b69642d636865636b2d64696769742f762f737461626c65)](https://packagist.org/packages/ilexn/hkid-check-digit)[![Total Downloads](https://camo.githubusercontent.com/5085ec3d641ec050eaf3a35d7cae0c0bd625b779e5f59cbbc1eafa5bcac14ecf/68747470733a2f2f706f7365722e707567782e6f72672f696c65786e2f686b69642d636865636b2d64696769742f646f776e6c6f616473)](https://packagist.org/packages/ilexn/hkid-check-digit)

[![GitHub Action](https://github.com/iLexN/HKID-Check-Digit/actions/workflows/ci.yaml/badge.svg)](https://github.com/iLexN/HKID-Check-Digit/actions/workflows/ci.yaml)[![Coverage Status](https://camo.githubusercontent.com/2eae25ef71d27e38bd2c33d8ff67dcfceab1cec15be1863beed33a38246b9bee/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f694c65784e2f484b49442d436865636b2d44696769742f62616467652e7376673f6272616e63683d362e78)](https://coveralls.io/github/iLexN/HKID-Check-Digit?branch=6.x)[![Mutation testing badge](https://camo.githubusercontent.com/85b89d289bcc8dc2c27fdc028540ef8d81944fa97f1031a96e4ab7b0b703d4f0/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d253246694c65784e253246484b49442d436865636b2d4469676974253246362e78)](https://dashboard.stryker-mutator.io/reports/github.com/iLexN/HKID-Check-Digit/6.x)

[![Ask DeepWiki](https://camo.githubusercontent.com/0f5ae213ac378635adeb5d7f13cef055ad2f7d9a47b36de7b1c67dbe09f609ca/68747470733a2f2f6465657077696b692e636f6d2f62616467652e737667)](https://deepwiki.com/iLexN/HKID-Check-Digit)

TagPHP1.x2.xphp&gt;=7.13.xphp&gt;=7.44.xphp&gt;=8.05.xphp&gt;=8.16.xphp&gt;=8.4Installation
------------

[](#installation)

```
composer require ilexn/hkid-check-digit
```

Upgrade from 5.x to 6.x
-----------------------

[](#upgrade-from-5x-to-6x)

The `\Ilex\Validation\HkidValidation\Enum\Reason::PattenError` changed to `\Ilex\Validation\HkidValidation\Enum\Reason::PatternError`

This has the incorrect spelling in the previous version.

Upgrade from 4.x to 5.x
-----------------------

[](#upgrade-from-4x-to-5x)

The `\Ilex\Validation\HkidValidation\Reason\ReasonInterface` changed to Enum `\Ilex\Validation\HkidValidation\Enum\Reason`

```
//4.x
switch ($hkid->getReason()){
    case \Ilex\Validation\HkidValidation\Reason\ReasonInterface::OK:
        echo('correct');
        echo($hkid->format());
        break;
    case \Ilex\Validation\HkidValidation\Reason\ReasonInterface::PATTEN_ERROR:
        echo('Pattern not match');
        break;
    case \Ilex\Validation\HkidValidation\Reason\ReasonInterface::DIGIT_ERROR:
        echo('Digit not match');
        break;
}

//5.x
switch ($hkid->getReason()){
    case \Ilex\Validation\HkidValidation\Enum\Reason::Ok:
        echo('correct');
        echo($hkid->format());
        break;
    case \Ilex\Validation\HkidValidation\Enum\Reason::PattenError:
        echo('Pattern not match');
        break;
    case \Ilex\Validation\HkidValidation\Enum\Reason::DigitError:
        echo('Digit not match');
        break;
}
```

Upgrade from 2.x to 3.x
-----------------------

[](#upgrade-from-2x-to-3x)

All the checking now return `\Ilex\Validation\HkidValidation\HkId` object, not `bool`

```
