Skip to content

Lightweight library for working with government-issued personal identification codes.

License

Notifications You must be signed in to change notification settings

vladislavgoltjajev/java-personal-code

Repository files navigation

Java Personal Code

Maven Central License

Lightweight library for working with government-issued personal identification codes.

Import

Java 8 or higher is required for the library to work.

Gradle

dependencies {
    implementation 'com.github.vladislavgoltjajev:java-personal-code:X.X'
}

Maven

<dependency>
    <groupId>com.github.vladislavgoltjajev</groupId>
    <artifactId>java-personal-code</artifactId>
    <version>X.X</version>
</dependency>

Usage

public class Test {

    /**
     * Example operations using an Estonian personal code.
     */
    public static void main(String[] args) {
        // Generate personal code.
        EstonianPersonalCodeGenerator generator = new EstonianPersonalCodeGenerator();
        String personalCode = generator.generateRandomPersonlCode(); // 37209030023
        // Validate personal code.
        EstonianPersonalCodeValidator validator = new EstonianPersonalCodeValidator();
        boolean isValidFormat = validator.isValidFormat(personalCode); // true
        boolean isValid = validator.isValid(personalCode); // true
        // Extract data from personal code.
        EstonianPersonalCodeParser parser = new EstonianPersonalCodeParser();
        LocalDate dateOfBirth = parser.getDateOfBirth(personalCode); // 03.09.1972
        Gender gender = parser.getGender(personalCode); // MALE
        int birthOrderNumber = parser.getBirthOrderNumber(personalCode); // 2
    }
}

API

Estonia

GYYMMDDXXXC

  • G - gender and birth century indicator (1, 3, 5 - male; 2, 4, 6 - female)
  • YYMMDD - date of birth
  • XXX - birth order number
  • C - checksum

Example: 47508030046.

EstonianPersonalCodeValidator

Method Return type Description
isValid(String personalCode) boolean Checks if the Estonian personal code is valid.
isValidFormat(String personalCode) boolean Checks if the Estonian personal code conforms to the correct format.
Does not check the integrity of the personal code or the validity of the embedded data.

EstonianPersonalCodeParser

Method Return type Description
getGender(String personalCode) Gender Returns the person's gender (first digit).
getDateOfBirth(String personalCode) LocalDate Returns the person's date of birth (digits 2-7).
getAge(String personalCode) Period Returns the person's age.
getBirthOrderNumber(String personalCode) int Returns the person's birth order number (digits 8-10).

EstonianPersonalCodeGenerator

Method Return type Description
generateRandomPersonalCode() String Generates a random Estonian personal code.
generatePersonalCode(Gender gender) String Generates an Estonian personal code using the given gender.
The date of birth and birth order number are generated randomly.
generatePersonalCode(Gender gender, LocalDate dateOfBirth) String Generates an Estonian personal code using the given gender and date of birth.
The birth order number is generated randomly.
generatePersonalCode(Gender gender, LocalDate dateOfBirth, int birthOrderNumber) String Generates an Estonian personal code using the given gender, date of birth and birth order number.

India

XXXX-XXXX-XXXC

  • XXXX-XXXX-XXX - random numbers
  • C - checksum (Verhoeff algorithm)

Example: 9185-8655-0944.

IndianPersonalCodeValidator

Method Return type Description
isValid(String personalCode) boolean Checks if the Indian personal code is valid.
isValidFormat(String personalCode) boolean Checks if the Indian personal code conforms to the correct format.
Does not check the integrity of the personal code.

IndianPersonalCodeGenerator

Method Return type Description
generatePersonalCode() String Generates an Indian personal code.

Latvia

32XXXX-XXXXC (updated format since 01.07.2017)

  • 32 - updated format indicator
  • XXXX-XXXX - random numbers
  • C - checksum

Example: 323691-93794.

YYMMDD-BXXXC (legacy format)

  • YYMMDD - date of birth
  • B - birth century indicator (0 - 19th, 1 - 20th, 2 - 21st)
  • XXX - birth order number
  • C - checksum

Example: 290156-11605.

LatvianPersonalCodeValidator

Method Return type Description
isValid(String personalCode) boolean Checks if the Latvian personal code (either updated or legacy) is valid.
isValidUpdatedPersonalCode(String personalCode) boolean Checks if the updated Latvian personal code is valid.
isValidLegacyPersonalCode(String personalCode) boolean Checks if the legacy Latvian personal code is valid.
isValidFormat(String personalCode) boolean Checks if the specified Latvian personal code conforms to the correct legacy or updated format.
Does not check the integrity of the personal code or the validity of the embedded data.
isValidUpdatedFormat(String personalCode) boolean Checks if the updated Latvian personal code conforms to the correct format.
Does not check the integrity of the personal code.
isValidLegacyFormat(String personalCode) boolean Checks if the legacy Latvian personal code conforms to the correct format.
Does not check the integrity of the personal code or the validity of the embedded data.

LatvianPersonalCodeParser

❗ Only works with legacy Latvian personal codes.

Method Return type Description
getDateOfBirth(String personalCode) LocalDate Returns the person's date of birth (digits 1-6).
getAge(String personalCode) Period Returns the person's age.
getBirthOrderNumber(String personalCode) int Returns the person's birth order number (digits 8-10).

LatvianPersonalCodeGenerator

Method Return type Description
generateRandomPersonalCode() String Generates a random Latvian personal code.
generateRandomUpdatedPersonalCode() String Generates a random updated Latvian personal code.
May contain a dash between the 6th and 7th digit.
generateRandomUpdatedPersonalCode(boolean addDash) String Generates a random updated Latvian personal code.
generateRandomLegacyPersonalCode() String Generates a random legacy Latvian personal code.
generateLegacyPersonalCode(LocalDate dateOfBirth) String Generates a legacy Latvian personal code using the given date of birth.
The birth order number is generated randomly.
generateLegacyPersonalCode(LocalDate dateOfBirth, int birthOrderNumber) String Generates a legacy Latvian personal code using the given date of birth and birth order number.

Lithuania

GYYMMDDXXXC

  • G - gender and birth century indicator (1, 3, 5 - male; 2, 4, 6 - female)
  • YYMMDD - date of birth
  • XXX - birth order number
  • C - checksum

Example: 50109130003.

LithuanianPersonalCodeValidator

Method Return type Description
isValid(String personalCode) boolean Checks if the Lithuanian personal code is valid.
isValidFormat(String personalCode) boolean Checks if the Lithuanian personal code conforms to the correct format.
Does not check the integrity of the personal code or the validity of the embedded data.

LithuanianPersonalCodeParser

Method Return type Description
getGender(String personalCode) Gender Returns the person's gender (first digit).
getDateOfBirth(String personalCode) LocalDate Returns the person's date of birth (digits 2-7).
getAge(String personalCode) Period Returns the person's age.
getBirthOrderNumber(String personalCode) int Returns the person's birth order number (digits 8-10).

LithuanianPersonalCodeGenerator

Method Return type Description
generateRandomPersonalCode() String Generates a random Lithuanian personal code.
generatePersonalCode(Gender gender) String Generates a Lithuanian personal code using the given gender.
The date of birth and birth order number are generated randomly.
generatePersonalCode(Gender gender, LocalDate dateOfBirth) String Generates a Lithuanian personal code using the given gender and date of birth.
The birth order number is generated randomly.
generatePersonalCode(Gender gender, LocalDate dateOfBirth, int birthOrderNumber) String Generates a Lithuanian personal code using the given gender, date of birth and birth order number.

Luxembourg

YYYYMMDDXXXCC

  • YYYYMMDD - date of birth
  • XXX - birth order number
  • CC - checksum (Luhn and Verhoeff algorithms)

Example: 1944051267737.

LuxembourgishPersonalCodeValidator

Method Return type Description
isValid(String personalCode) boolean Checks if the Luxembourgish personal code is valid.
isValidFormat(String personalCode) boolean Checks if the Luxembourgish personal code conforms to the correct format.
Does not check the integrity of the personal code or the validity of the embedded data.

LuxembourgishPersonalCodeParser

Method Return type Description
getDateOfBirth(String personalCode) LocalDate Returns the person's date of birth (digits 1-8).
getAge(String personalCode) Period Returns the person's age.
getBirthOrderNumber(String personalCode) int Returns the person's birth order number (digits 9-11).

LuxembourgishPersonalCodeGenerator

Method Return type Description
generateRandomPersonalCode() String Generates a random Luxembourgish personal code.
generatePersonalCode(LocalDate dateOfBirth) String Generates a Luxembourgish personal code using the given date of birth.
The birth order number is generated randomly.
generatePersonalCode(LocalDate dateOfBirth, int birthOrderNumber) String Generates a Luxembourgish personal code using the given date of birth and birth order number.

Taiwan

RGXXXXXXXC

  • R - household registration region (A-Z)
  • G - gender indicator (1 - male, 2 - female)
  • XXXXXXX - random number
  • C - checksum

Example: R172192293.

TaiwanesePersonalCodeValidator

Method Return type Description
isValid(String personalCode) boolean Checks if the Taiwanese personal code is valid.
isValidFormat(String personalCode) boolean Checks if the Taiwanese personal code conforms to the correct format.
Does not check the integrity of the personal code.

TaiwanesePersonalCodeParser

Method Return type Description
getHouseholdRegistrationRegion(String personalCode) TaiwaneseRegion Returns the person's household registration region (first letter).
getGender(String personalCode) Gender Returns the person's gender (first digit).

TaiwanesePersonalCodeGenerator

Method Return type Description
generateRandomPersonalCode() String Generates a random Taiwanese personal code.
generatePersonalCode(TaiwaneseRegion region) String Generates a Taiwanese personal code using the given household registration region.
The gender is generated randomly.
generatePersonalCode(Gender gender) String Generates a Taiwanese personal code using the given gender.
The household registration region is generated randomly.
generatePersonalCode(TaiwaneseRegion region, Gender gender) String Generates a Taiwanese personal code using the given household registration region and gender.
The household registration region is not checked for validity.
generatePersonalCode(TaiwaneseRegion region, Gender gender, boolean checkRegionValidity) String Generates a Taiwanese personal code using the given household registration region and gender and checks if the given household registration region is valid.

United Arab Emirates

784-YYYY-XXXXXXX-C

  • 784 - ISO 3166-1 numeric code for the UAE
  • YYYY - year of birth
  • XXXXXXX - random number
  • C - checksum (Luhn algorithm)

Example: 784-1935-0284231-8.

EmiratiPersonalCodeValidator

Method Return type Description
isValid(String personalCode) boolean Checks if the Emirati personal code is valid.
isValidFormat(String personalCode) boolean Checks if the Emirati personal code conforms to the correct format.
Does not check the integrity of the personal code.

EmiratiPersonalCodeParser

Method Return type Description
getBirthYear(String personalCode) int Returns the person's birth year (digits 4-7).

EmiratiPersonalCodeGenerator

Method Return type Description
generateRandomPersonalCode() String Generates a random Emirati personal code.
generatePersonalCode(LocalDate dateOfBirth) String Generates an Emirati personal code using the given date of birth.
generatePersonalCode(int birthYear) String Generates an Emirati personal code using the given birth year.

About

Lightweight library for working with government-issued personal identification codes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages