Library for validation of Polish NIP, PESEL, REGON for C# (.NET Standard)
Most validation algorithms are published separate. They differ only in weights and checksum function. That's why I decided to write a simple implementation for C# using Template Method design pattern.
PolishValidators can be installed using the Nuget package manager or the dotnet CLI.
Install-Package PolishValidators
dotnet add package PolishValidators
IValidator validator = new PeselValidator();
bool result = validator.IsValid("49040501580");
IValidator validator = new NipValidator();
bool result = validator.IsValid("9531204591");
You can easily create a new validator. Just use abstract class ValidatorBase and override Weights and sum control function like this:
public class CustomValidator : ValidatorBase
{
protected override byte[] Weights => new byte[] { 1, 5, 7, 9, 1, 5, 7, 9, 5, 3 };
protected override int CheckControl(int sumControl) => 10 - sumControl % 10;
}
Good luck :)
If you are looking for route constraints for MVC or Razor Pages projects then I invite you my another project using PolishValidators library: https://github.com/sulmar/dotnet-core-routecontraint-polish-validators