2017 © Pedro Peláez
 

library hkid-util

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

image

yhdleung/hkid-util

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

  • Thursday, March 9, 2017
  • by yhdleung
  • Repository
  • 1 Watchers
  • 1 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 20 % Grown

The README.md

HKIDUtil

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

Latest Stable Version License, (*2)

Features

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

Requirement

  • PHP 5.3+

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

Include the utility function file, (*3)

require_once("HKIDUtil.php");

Usage

Get the Check Digit of a HKID, (*4)

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

Validate HKID format, check digit parentheses are optional, (*5)

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

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

Generate random HKID, (*6)

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', (*7)

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

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

Reference

This HKID validation formula is developed based on the information from Wikipedia.
維基百科, 香港身份證 (Wikipedia, Hong Kong Identity Card), (*9)

Contribution

Star, fork, pull request and issue report are all welcome., (*10)

The Versions

09/03 2017

dev-master

9999999-dev https://github.com/yhdleung/HKIDUtil

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar yhdleung

hong kong hkid hong kong identity card

09/03 2017

1.0

1.0.0.0 https://github.com/yhdleung/HKIDUtil

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar yhdleung

hong kong hkid hong kong identity card