Java library for validating and decoding PESEL (Powszechny Elektroniczny System Ewidencji Ludności, Universal Electronic System for Registration of the Population).
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>
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
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
}