Coder Social home page Coder Social logo

iban4net's Introduction

IBAN4Net

A port of Artur Mkrtchyan's IBAN4j project to .NET. Artur's project can be found here

IBAN4Net is a library for generation and validation of the International Bank Account Numbers (IBAN) and Business Identifier Codes (BIC).

More information about IBANs and BICs can be found here:

This library is written in C# ver. 6.0 and it is not a one-to-one port of the original IBAN4j project. It contains some tweaks here and there and it doesn't support random IBAN generation, yet.

Some of the differencies from the java project are:

  • CountryCode dictionary contains definitions for all of the countries (I hope)
  • Instead of valueOf(), I'm using a pattern of CreateInstance()
  • Iban Builder verifies lengths of some of the parts during formatting and can left-pad them with zeroes if they are shorter than BBAN rule specifies. This feature is enabled by default, but can be disabled (see examples).
  • Validation of IBAN and BIC can be done without exceptions (see examples)

You can get this library directly to your project from NuGet: https://www.nuget.org/packages/IBAN4Net/

Quick examples of usage:

IBANs:

// How to generate IBAN:
Iban iban = new IbanBuilder()
                .CountryCode( CountryCode.GetCountryCode( "CZ" ) )
                .BankCode( "0800" )
                .AccountNumberPrefix( "000019" )
                .AccountNumber( "2000145399" )   
                .Build(); 

// iban.ToString() = CZ6508000000192000145399

// or with autopadding (supplement missing zeroes):
Iban iban = new IbanBuilder()
                .CountryCode( CountryCode.GetCountryCode( "CZ" ) )
                .BankCode( "800" )
                .AccountNumberPrefix( "19" )
                .AccountNumber( "2000145399" )   
                .Build(); 

// iban.ToString() = CZ6508000000192000145399

// disable autopadding:
Iban iban = new IbanBuilder()
                .CountryCode( CountryCode.GetCountryCode( "CZ" ) )
                .BankCode( "800" )
                .AccountNumberPrefix( "19" )
                .AccountNumber( "2000145399" )   
                .Build(true, false); 


// How to get an IBAN object from IBAN string:
Iban iban = Iban.CreateInstance( "CZ6508000000192000145399" );

// How to get IBAN string from the IBAN object:
string iban = Iban.CreateInstance( "CZ6508000000192000145399" ).ToString();


// How to validate IBAN:
try
{
    IbanUtils.Validate("CZ6508000000192000145399");
}
catch (IbanFormatException iex)
{
    // invalid
}

// Validation of IBAN without throwing an exception:
IbanFormatViolation validationResult = IbanFormatViolation.NO_VIOLATION;
if (IbanUtils.IsValid("CZ6508000000192000145399", out validationResult))
{
    // valid IBAN
}
else
{
    // invalid IBAN
    // validationResult contains reason of unsuccessful validation
}

BICs:

// How to get an BIC object from string:
Bic testBic = Bic.CreateInstance( "DEUTDEFF500" );

// How to validate BIC:
try
{
    BicUtils.Validate("DEUTDEFF500");
}
catch (BicFormatException bex)
{
    // invalid
}

// Validation of BIC without throwing an exception:
BicFormatViolation validationResult = BicFormatViolation.NO_VIOLATION;
if (BicUtils.IsValid("DEUTDEFF500", out validationResult))
{
    // valid BIC
}
else
{
    // invalid BIC
    // validationResult contains reason of unsuccessful validation
}

References

License

Copyright 2015 Vaclav Beca [sinkien].

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

iban4net's People

Contributors

ant-1 avatar christos-pavlides avatar sinkien avatar

Watchers

 avatar  avatar

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.