IbanNet 3.0.0

There is a newer version of this package available.
See the version list below for details.
Install-Package IbanNet -Version 3.0.0
dotnet add package IbanNet --version 3.0.0
<PackageReference Include="IbanNet" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IbanNet --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: IbanNet, 3.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install IbanNet as a Cake Addin
#addin nuget:?package=IbanNet&version=3.0.0

// Install IbanNet as a Cake Tool
#tool nuget:?package=IbanNet&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

IbanNet

IbanNet is a .NET library providing functionality to validate and parse an International Bank Account Number also known as IBAN.

Usage

Parse

The simplest way to use this library is to use the static Parse method:

Iban iban = Iban.Parse("NL91ABNA0417164300");

When parsing fails, an IbanFormatException is thrown, which contains a property Result which indicates the type of error that occurred.

TryParse

To parse an IBAN without throwing an exception use TryParse.

Iban iban;
bool success = Iban.TryParse("NL91ABNA0417164300", out iban);

The only downside is there is no way to retrieve the type of validation error that occurred if parsing fails.

IbanValidator

Lastly, you can use the validator directly. The benefit of using the validator is that it implements the IIbanValidator interface and can thus be mocked. Additionally, the ValidationResult provides extra context, like the matched country (if any).

For example:

IIbanValidator validator = new IbanValidator();
ValidationResult validationResult = validator.Validate("NL91ABNA041716430");
if (validationResult.IsValid) {
  // For example:
  if (validationResult.Country.TwoLetterISORegionName != "NL") {
    throw new InvalidOperationException("Please provide a Dutch bank account.");
  }
}

Iban type

Iban.Parse and Iban.TryParse return a type Iban. The Iban type is entirely optional, and if you use the validator directly you won't ever need to use this type.

However, this type does provide some useful features:

Format IBAN

To convert an Iban type to a string, call the ToString(string format) method with either of 2 formats:

"F" or IbanNet.Iban.Formats.Flat = NL91ABNA0417164300 "S" or IbanNet.Iban.Formats.Partitioned = NL91 ABNA 0417 1643 00

If ToString() is called without format, defaults to 'F'.

Equals

Whether you parsed NL91 ABNA 0417 1643 00 or NL91ABNA0417164300, these IBAN are considered equal.

Mocking the static Parse/TryParse methods

If you use the static methods because you would like to use the Iban type, you can still mock the underlying validator for testing purposes by setting the static property Iban.Validator.

Installation

Install IbanNet via NuGet.

Visual Studio / .NET Framework

Install-Package IbanNet

.NET CLI

dotnet add package IbanNet

Supported .NET targets

  • .NET 4.5 or greater
  • .NET Standard 1.2 or greater

Requirements

  • Visual Studio 2017
  • .NET Core 2.0 SDK
Contributions

PR's are welcome. Please rebase before submitting, provide test coverage, and ensure the AppVeyor build passes. I will not consider PR's otherwise.

Contributors
  • skwas (author/maintainer)

Useful info

NuGet packages (6)

Showing the top 5 NuGet packages that depend on IbanNet:

Package Downloads
IbanNet.FluentValidation

FluentValidation support to validate IBAN user input.

IbanNet.DataAnnotations

Data annotations to validate IBAN user input.

IbanNet.DependencyInjection.ServiceProvider

Microsoft.Extensions.DependencyInjection integration for IbanNet; IbanNet provides an IBAN validator and parser.

IdokladSdk

SDK for iDoklad API

IbanNet.DependencyInjection.Autofac

Autofac IoC container integration for IbanNet; IbanNet provides an IBAN validator and parser.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.3.1 1,653 11/14/2021
5.3.0 198 11/13/2021
5.2.0 1,331 11/10/2021
5.1.0 13,743 9/27/2021
5.0.0 11,029 8/21/2021
5.0.0-beta0001 447 6/17/2021
4.4.3 961 8/21/2021
4.4.2 28,713 6/17/2021
4.4.1 2,742 6/13/2021
4.4.0 1,323 6/12/2021
4.3.1 25,005 6/5/2021
4.3.0 170,479 11/27/2020
4.2.0 5,866 11/7/2020
4.1.0 50,172 8/8/2020
4.0.1 88,332 5/12/2020
4.0.0 31,843 2/8/2020
4.0.0-beta0241 530 2/8/2020
4.0.0-beta0227 406 2/8/2020
4.0.0-beta0223 571 2/8/2020
4.0.0-beta0222 549 2/8/2020
4.0.0-beta0204 492 2/6/2020
4.0.0-beta0190 498 1/14/2020
4.0.0-beta0187 550 1/13/2020
4.0.0-beta0186 408 1/13/2020
4.0.0-beta0183 462 1/13/2020
4.0.0-beta0178 11,280 12/30/2019
4.0.0-beta0177 440 12/29/2019
4.0.0-beta0172 499 12/29/2019
3.2.2 393 5/12/2020
3.2.1 33,348 1/14/2020
3.2.0 13,861 11/23/2019
3.1.2 1,076 10/25/2019
3.1.1 9,297 7/25/2019
3.1.0 20,042 5/10/2019
3.0.0 32,533 2/14/2019
2.1.0 25,736 9/18/2018
2.0.0 12,605 2/3/2018
1.2.0 874 12/25/2017
1.1.16 781 12/25/2017
1.0.19 875 12/25/2017
1.0.18 714 12/25/2017
1.0.17 779 12/25/2017