jahav / czech-identifiers

A project to parse and validate various identifiers used in Czech Republic (e.g. birth number, IČO..).
https://jahav.github.io/czech-identifiers/
MIT License
0 stars 1 forks source link

czech-identifiers

A project to parse and validate various identifiers used in Czech Republic (e.g. birth number, IČO..).

Build status codecov

Documentation

You can find the complete documentation at https://jahav.github.io/czech-identifiers/.

Usage

There are three identifier so far:

All of these classes follow this use pattern:

// First choose a pattern from [identifier]Pattern class. Generally, there is always a standard pattern, possibly others.
ParseResult<BirthNumber> parseResult = BirthNumberPattern.StandardPattern.Parse("780123/3540");
if (!parseResult.Success)
{
    Console.WriteLine("Birth number couldn't be parsed.");
    return;
}

Console.WriteLine("Birth number was successfully parsed, but we don't know yet if it is valid or not.");

// Get a parsed value
BirthNumber birthNumber = parseResult.Value;

// check if it is valid, it might be or it might not.
if (birthNumber.IsValid)
{
    Console.WriteLine("Birth number is is valid for a {0} born at {1:d}.", birthNumber.BelongsToWoman ? "woman" : "man", birthNumber.DateOfBirth);
}
else
{
    Console.WriteLine("Birth number is invalid, expected check digit to be {0}.", birthNumber.ExpectedCheckDigit);
}

This code will output

Birth number was successfully parsed, but we don't know yet if it is valid or not.

Birth number is is valid for a man born at 23.1.1978.

Design principles

Basically if you ever worked in a bank, you know you often get a garbage as an input. You get an IBAN where you should get BIC, you get wrong invalid data all the time.

IČO (IdentificationNumber)

IČO is an 8 digit identifier of a legal person in a czech republic. It is used for companies and for self-employed persons. The IČO consists of 7 number digits and eigth check digit.

You can fing companies at https://justce.cz and self-employed persons at http://www.rzp.cz.

It seems that official sources describing validation algorithm are sparse/nonexistent when it comes to the validation of IČO, so I ended up with https://phpfashion.com/jak-overit-platne-ic-a-rodne-cislo.

Building NuGet package