Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sulmar/polish-validators
Library for validation of Polish NIP, PESEL, REGON
https://github.com/sulmar/polish-validators
csharp nip-validation pesel-validation polish
Last synced: 16 days ago
JSON representation
Library for validation of Polish NIP, PESEL, REGON
- Host: GitHub
- URL: https://github.com/sulmar/polish-validators
- Owner: sulmar
- Created: 2020-04-30T09:50:27.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-13T09:52:10.000Z (over 1 year ago)
- Last Synced: 2024-11-08T21:13:22.519Z (2 months ago)
- Topics: csharp, nip-validation, pesel-validation, polish
- Language: C#
- Size: 25.4 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Polish Validators for C#
Library for validation of Polish NIP, PESEL, REGON for C# (.NET Standard)## Description
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.## Get Started
PolishValidators can be installed using the Nuget package manager or the dotnet CLI.~~~
Install-Package PolishValidators
~~~~~~
dotnet add package PolishValidators
~~~## Usage
~~~ csharp
IValidator validator = new PeselValidator();
bool result = validator.IsValid("49040501580");
~~~~~~ csharp
IValidator validator = new NipValidator();
bool result = validator.IsValid("9531204591");
~~~## Custom Validator
You can easily create a new validator.
Just use abstract class _ValidatorBase_ and override _Weights_ and sum control function like this:~~~ csharp
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 :)
## Route constraints
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/Sulmar.AspNetCore.Routing.RouteConstraints