GithubHelp home page GithubHelp logo

iban4net's Introduction

IBAN4Net

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

This project is a port of Artur Mkrtchyan's IBAN4j project to .NET (netstandard). Artur's project can be found here.

More information about IBANs and BICs can be found here:

This library is written with 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.

Since 10/2022 the library contains definitions for all countries with IBAN support listed as Partial/Experimental. Definitions for those countries are...vague at best. Take that as a warning. PRs better clarifying those rules are much welcomed.

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
}

// Check if IBAN is from SEPA member country
bool ibanFromSEPA = IbanUtils.IsFromSEPACountry("CZ5508000000001234567899"); // true

// Check if IBAN is from SEPA Eurozone (uses EUR as currency) member country
bool ibanWithEUR = IbanUtils.IsFromEurozoneSEPACountry("FI1410093000123458"); // true

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
}

Contribute and PRs

I don't like PRs supporting the everlasting "tabs vs. spaces" battle. Main project contains .editorconfig (VS2022) file which sets the score clearly ;)

I'm really sorry for a rather long delays when accepting PRs.

References

License

Copyright 2022 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 captainroot avatar deathgore avatar dsidirop avatar sinkien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iban4net's Issues

Can be build with Framework 4

Hi,

I have to use this wonderful dll with an old project in Framework 4.

When I try to integrate Iban4net, there were no warning but it can't compile.

When I switch in 4.5 there was no problem.

So I download the code, downgrade the framework to 4 and recompile. There were no error and everything seems to be ok.

Of course, there were warning in the tests projects but the Iban4net project was good.

I hope to be as explicit as I can

Thanks a lot for your great job

BaesFr

UnsupportedCountryException for Irish IBAN

Validation of IE92BOFI90001710027952 thows an UnsupportedCountryException ("IBAN contains not supported country code").
According to iban.com, iban.de and iban-rechner.de the IBAN is perfectly valid and I don't see why Ireland should be in the list of supported countries.

Country Code IE not supported

Getting error when using an IE IBAN with IbanUtils.Validate

sinkien.IBAN4Net.UnsupportedCountryException: 'IBAN contains not supported country code'

IBANs used:
IE29AIBK93115212345678
IE64BOFI90001720974097

It is working fine for other IBANs I tried from other countries.

IBAN not recognized

whatsapp image 2018-10-12 at 1 14 24 am
BH14SCBLBHD18905826101 is a valid iban number but when i passed this iban to IbanUtils.Validate it says
'BHD18905826101' must contain only digits
sinkien.IBAN4Net.IbanFormatViolation.BBAN_ONLY_DIGITS

Add Support for Morocco IBANs (plus countries which have "experimental" support for IBANs)

For instance this one:

MA64011519000001205000534921

Even though valid it results in country-not-supported

Here's the complete list of countries that need to be supported:

b = National bank code
s = Branch code
c = Account number

Central African Republic 27 23n CFkk nnnn nnnn nnnn nnnn nnnn nnn [CF 42 20001000010120069700160]
Chad 27 23n TDkk nnnn nnnn nnnn nnnn nnnn nnn [TD 89 60002000010271091600153]
Comoros 27 23n KMkk nnnn nnnn nnnn nnnn nnnn nnn [KM 46 00005000010010904400137]
Congo, Republic of the 27 23n CGkk nnnn nnnn nnnn nnnn nnnn nnn [CG 39 30011000101013451300019]
Côte d'Ivoire 28 1a, 23n CIkk annn nnnn nnnn nnnn nnnn nnnn [CI 77 A 12312341234123412341234]
Djibouti 27 23n DJkk nnnn nnnn nnnn nnnn nnnn nnn [DJ 21 10002010010409943020008]
Equatorial Guinea 27 23n GQkk nnnn nnnn nnnn nnnn nnnn nnn [GQ 70 50002001003715228190196]
Gabon 27 23n GAkk nnnn nnnn nnnn nnnn nnnn nnn [GA 21 40021010032001890020126]
Guinea-Bissau 25 2c, 19n GWkk ccnn nnnn nnnn nnnn nnnn n [GW 04 GW1430010181800637601]
Honduras 28 4a, 20n HNkk aaaa nnnn nnnn nnnn nnnn nnnn [HN 54 PISA00000000000000123124]
Morocco 28 24n MAkk nnnn nnnn nnnn nnnn nnnn nnnn [MA 64 011519000001205000534921]
Nicaragua 32 4a, 24n NIkk aaaa nnnn nnnn nnnn nnnn nnnn nnnn [NI 92 BAMC000000000000000003123123]
Niger 28 2a, 22n NEkk aann nnnn nnnn nnnn nnnn nnnn [NE 58 NE0380100100130305000268]
Togo 28 2a, 22n TGkk aann nnnn nnnn nnnn nnnn nnnn [TG 53 TG0090604310346500400070]
Libya 25 21n LYkk bbbs sscc cccc cccc cccc c [LY 83 002048000020100120361]

Source:

https://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country

IBAN is not recognized as valid.

Hi,

The following valid IBAN was tested by your library, but it returned an error (CHECK_DIGIT_ONLY_DIGITS).

Valid IBAN: NL 91 ABNA 8571 1893 58

AN country code not supported for BIC

Validation of:
MIDCANC1XXX
NCBCANC1XXX
NEANANCUXXX
MEESANCUCUR
INDSANCUXXX
EINBANCUXXX
....

rise a "Country code not supported error" message
AN country code stands for Netherlands Antilles

Niger BBAN is not supported

Hi,
I have a IBAN coming from Niger which is not supported by your library, can you add it please ?
Here is the specifications:
image

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.