Skip to content

mariuszfoltak/polish-identification-numbers

Repository files navigation

Polish Identification Numbers utils

Maven Central GitHub Build Status Quality Gate Status Coverage

Java library for validating and decoding PESEL (Powszechny Elektroniczny System Ewidencji Ludności, Universal Electronic System for Registration of the Population).

Installation

Library is available in Central Maven Repository. Include the library as a dependency in your pom.xml

<dependencies>
    <dependency>
        <groupId>pl.foltak.polish-identification-numbers-utils</groupId>
        <artifactId>polish-identification-numbers-utils</artifactId>
        <version>1.0.0</version>
    </dependency>
    ...
</dependencies>

Usage

Validating PESEL number

To validate PESEL use PeselValidator class

import pl.foltak.polishidnumbers.pesel.PeselValidator;
import pl.foltak.polishidnumbers.pesel.InvalidPeselException;

...

PeselValidator peselValidator = new PeselValidator();
boolean isPeselValid = peselValidator.isValid("79461078451");
// or
try {
    peselValidator.assertIsValid("79461078451");
} catch (InvalidPeselException e) {
    PeselConstraint violation = e.getPeselConstraint();
    // handle exception
}

InvalidPeselException has peselConstraint field which contains information about violation of invalid pesel number like:

  • incorrect length,
  • incorrect characters,
  • incorrect check digit,
  • incorrect birth date

Decoding PESEL information

To decode birth date or person sex from PESEL use Pesel class

import pl.foltak.polishidnumbers.pesel.Pesel;
import pl.foltak.polishidnumbers.pesel.InvalidPeselException;

...

try {
    Pesel pesel = new Pesel("79461078451");
    LocalDate birthDate = pesel.getBirthDate();
    Pesel.Sex sex = pesel.getSex();
} catch (InvalidPeselException e) {
    PeselConstraint violation = e.getPeselConstraint();
    // handle exception
}

License

MIT

About

Java library for validating and decoding PESEL (Powszechny Elektroniczny System Ewidencji Ludności, Universal Electronic System for Registration of the Population).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages