Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.77 KB

README.md

File metadata and controls

52 lines (40 loc) · 1.77 KB

HKIDNumber Library

The HKIDNumber library provides a comprehensive solution for generating, validating, and formatting Hong Kong Identity Card (HKID) numbers according to the official specifications. It is designed for use in Java applications that require handling HKID numbers, offering features like custom exceptions for invalid formats and check digits, and methods for random HKID number generation.

Features

  • Validate HKID numbers for correct format and check digit.
  • Generate HKID numbers with specific or random values.
  • Format HKID numbers with or without check digits, including parentheses formatting.
  • Throw custom exceptions for invalid HKID formats and check digits.

Requirements

  • Java 8 or higher

Usage

Below are some examples of how to use the HKIDNumber library in your projects.

Validating an HKID Number

try {
    HKIDNumber hkid = new HKIDNumber("A123456(7)");
    System.out.println("HKID is valid.");
} catch (InvalidHKIDNumberFormatException | InvalidCheckDigitException e) {
    System.out.println("Invalid HKID: " + e.getMessage());
}

Or

if (HKIDNumber.validateCheckDigit("A123456", "3")){
        System.out.println("Check Digit is correct.");
}

Generating a Random HKID Number

HKIDNumber randomHkid = HKIDNumber.genRandomHkidNumber();
System.out.println("Random HKID: " + randomHkid.toString());

Formatting an HKID Number

HKIDNumber hkid = new HKIDNumber("A123456(7)");
System.out.println("Formatted HKID: " + hkid.toString(HKIDNumber.Format.Complete));

Contributing

Contributions are welcome! Please feel free to submit pull requests, report bugs, or suggest features through the GitHub issue tracker.

License

This project is licensed under the MIT License. See the LICENSE file for details.