Giter Site home page Giter Site logo

polish-validators's Introduction

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

IValidator validator = new PeselValidator();
bool result = validator.IsValid("49040501580");
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:

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

polish-validators's People

Contributors

sulmar avatar

Stargazers

 avatar  avatar  avatar

Forkers

olszewskidev

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.