Lightweight library for working with government-issued personal identification codes.
Java 8 or higher is required for the library to work.
dependencies {
implementation 'com.github.vladislavgoltjajev:java-personal-code:X.X'
}
<dependency>
<groupId>com.github.vladislavgoltjajev</groupId>
<artifactId>java-personal-code</artifactId>
<version>X.X</version>
</dependency>
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
}
}
GYYMMDDXXXC
G
- gender and birth century indicator (1, 3, 5 - male; 2, 4, 6 - female)YYMMDD
- date of birthXXX
- birth order numberC
- checksum
Example: 47508030046.
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. |
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). |
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. |
XXXX-XXXX-XXXC
XXXX-XXXX-XXX
- random numbersC
- checksum (Verhoeff algorithm)
Example: 9185-8655-0944.
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. |
Method | Return type | Description |
---|---|---|
generatePersonalCode() | String | Generates an Indian personal code. |
32XXXX-XXXXC
(updated format since 01.07.2017)
32
- updated format indicatorXXXX-XXXX
- random numbersC
- checksum
Example: 323691-93794.
YYMMDD-BXXXC
(legacy format)
YYMMDD
- date of birthB
- birth century indicator (0 - 19th, 1 - 20th, 2 - 21st)XXX
- birth order numberC
- checksum
Example: 290156-11605.
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. |
❗ 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). |
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. |
GYYMMDDXXXC
G
- gender and birth century indicator (1, 3, 5 - male; 2, 4, 6 - female)YYMMDD
- date of birthXXX
- birth order numberC
- checksum
Example: 50109130003.
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. |
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). |
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. |
YYYYMMDDXXXCC
YYYYMMDD
- date of birthXXX
- birth order numberCC
- checksum (Luhn and Verhoeff algorithms)
Example: 1944051267737.
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. |
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). |
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. |
RGXXXXXXXC
R
- household registration region (A-Z)G
- gender indicator (1 - male, 2 - female)XXXXXXX
- random numberC
- checksum
Example: R172192293.
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. |
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). |
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. |
784-YYYY-XXXXXXX-C
784
- ISO 3166-1 numeric code for the UAEYYYY
- year of birthXXXXXXX
- random numberC
- checksum (Luhn algorithm)
Example: 784-1935-0284231-8.
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. |
Method | Return type | Description |
---|---|---|
getBirthYear(String personalCode) | int | Returns the person's birth year (digits 4-7). |
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. |