Development moved to this repo.
Extract personal data from and generate Estonian personal identification codes (isikukood) with this lightweight library.
The library is available on Maven Central and JCenter.
JDK 8 or higher is required for the library to work.
dependencies {
implementation 'com.github.vladislavgoltjajev:java-isikukood:2.1'
}
<dependency>
<groupId>com.github.vladislavgoltjajev</groupId>
<artifactId>java-isikukood</artifactId>
<version>2.1</version>
</dependency>
public class Test {
public static void main(String[] args) {
EstonianId estonianId = new EstonianId("47508030046");
boolean isValid = estonianId.isValid(); // true
String gender = estonianId.getGender(); // F
LocalDate dateOfBirth = estonianId.getDateOfBirth(); // 1975-08-03
Integer age = estonianId.getAge(); // 43
EstonianId invalidEstonianId = new EstonianId("123");
isValid = invalidEstonianId.isValid(); // false
gender = invalidEstonianId.getGender(); // null
dateOfBirth = invalidEstonianId.getDateOfBirth(); // null
age = invalidEstonianId.getAge(); // null
String personalCode = EstonianId.generateRandomPersonalCode(); // 35207049817
try {
gender = EstonianId.MALE;
dateOfBirth = LocalDate.of(1984, 3, 15);
personalCode = EstonianId.generatePersonalCode(gender, dateOfBirth); // 38403153949
personalCode = EstonianId.generatePersonalCode(gender, dateOfBirth, 7); // 38403150076
personalCode = EstonianId.generatePersonalCode("A", LocalDate.of(1799, 1, 1)); // Throws exception.
} catch (EstonianIdException e) {
// Handle exception.
}
}
}
Modifier and type | Field | Description |
---|---|---|
static String | FEMALE | Female gender classifier "F". |
static String | MALE | Male gender classifier "M". |
Constructor | Description |
---|---|
EstonianId(String personalCode) | Constructs a new EstonianId object using the specified personal code. |
Modifier and type | Method | Description |
---|---|---|
static String | generatePersonalCode(String gender, LocalDate dateOfBirth) | Generates a personal code using the specified gender and date of birth. Throws an exception if the gender is not "M" or "F" or the birth year is before 1800 or after 2099. |
static String | generatePersonalCode(String gender, LocalDate dateOfBirth, int birthOrderNumber) | Generates a personal code using the specified gender, date of birth and birth order number. Throws an exception if the gender is not "M" or "F", the birth year is before 1800 or after 2099 or the birth order number is less than 0 or more than 999. |
static String | generateRandomPersonalCode() | Generates a random personal code. |
Integer | getAge() | Calculates the person's age in years. Returns null if the personal code is invalid or the date of birth is in the future. |
LocalDate | getDateOfBirth() | Returns the person's date of birth. Returns null if the personal code is invalid. |
String | getGender() | Returns the person's gender ("M" or "F"). Returns null if the personal code is invalid. |
boolean | isValid() | Returns whether or not the personal code is valid. |
Please donate if you like my work.