Git Product home page Git Product logo

czech-identifiers's Introduction

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:

  • BirthNumber - identifier assigned to every natural person born in Czech Republic. If you are foreigner, you can ask for it. It is key identifier for medical care.
  • IdentificationNumber - IČO - identifier of legal persons.
  • AccountNumber - Czech bank account number

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.

  • Principle 0: Identifiers are immutable structs
  • Principle 1: Each identifier must be able to say whether it is a valid or invalid one
  • Principle 2: Don't just say valid/invalid. Offer properties to get data from the identifier
    • Example: Birth number has a date of birth, IČO has a number + checksum. These pieces of identifier can be retrieved using properties.
  • Principle 4: Offer parsers for various formats
    • Offer parsers that convert user input to standard format used by identifiers as best as it can. This is low priority.
    • I am using pattern similar to NodaTime - there are classes [identifier]Pattern that contain patterns used for parsing and formatting.

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

  • Open VS dev console Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/Tools/VsDevCmd.bat
  • Go to Identitifiers directory (there is csproj there)
  • run msbuild /t:pack /p:Configuration=Release
  • in bin/Release will be the Identifiers.Czech.*.nupkg package

czech-identifiers's People

Contributors

jahav avatar

Watchers

 avatar  avatar

Forkers

scholtz

czech-identifiers's Issues

Equals + hashcode

Implement Equals+HashCode, so identifiers can be used in the dictionaries. All identifiers are immutable anyway, so it should be easy.

Guard AccountNumber constructor parameters

AccountNumber constructor should have a guards against insertion of nonsensical numbers.

The prefix can be at most 6 digits long, so it should be in range 0-999999.
The number should be at most 10 digits long, so allowed range be 0-9999999999. It also should have at least two digits, but because it is a struct and can be created with all zeros anyway, I won't check that in constructor.

Not sure what to do about bank code.

Fix xml docs after implementation.

Číslo účtu

Create an country specific account number. It is being superseeded by IBAN, but it is still in widespread use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.