Skip to content

starteleport/IBAN4Net

 
 

Repository files navigation

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

About

A port of IBAN4j to .NET

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%