IbanNet 3.0.0

Provides an IBAN validator for verifying IBAN's.

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"
For F# scripts that support #r syntax, copy this into the source code to reference the package.

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

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 (5)

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.
IbanNet.DependencyInjection.Autofac
Autofac IoC container integration for IbanNet; IbanNet provides an IBAN validator and parser.
IbanNet.Extensions.Bban
IbanNet extension to validate BBAN national check digits.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
4.3.0 23,888 11/27/2020
4.2.0 3,185 11/7/2020
4.1.0 32,993 8/8/2020
4.0.1 44,306 5/12/2020
4.0.0 24,355 2/8/2020
4.0.0-beta0241 303 2/8/2020
4.0.0-beta0227 240 2/8/2020
4.0.0-beta0223 366 2/8/2020
4.0.0-beta0222 330 2/8/2020
4.0.0-beta0204 329 2/6/2020
4.0.0-beta0190 336 1/14/2020
4.0.0-beta0187 275 1/13/2020
4.0.0-beta0186 238 1/13/2020
4.0.0-beta0183 305 1/13/2020
4.0.0-beta0178 8,569 12/30/2019
4.0.0-beta0177 279 12/29/2019
4.0.0-beta0172 329 12/29/2019
3.2.2 171 5/12/2020
3.2.1 24,827 1/14/2020
3.2.0 10,040 11/23/2019
3.1.2 837 10/25/2019
3.1.1 7,583 7/25/2019
3.1.0 19,543 5/10/2019
3.0.0 27,511 2/14/2019
2.1.0 25,268 9/18/2018
2.0.0 11,989 2/3/2018
1.2.0 731 12/25/2017
1.1.16 648 12/25/2017
1.0.19 735 12/25/2017
1.0.18 581 12/25/2017
1.0.17 635 12/25/2017
Show less