Skip to content
Martijn Bodeman edited this page Aug 24, 2023 · 21 revisions

An IBAN can be parsed into an Iban type using the IbanParser class:

IIbanParser parser = new IbanParser(IbanRegistry.Default);
try
{
    Iban iban = parser.Parse("NL91 ABNA 0417 1643 00");
}
catch (IbanFormatException ex)
{
    if (ex.Result is InvalidCheckDigitsResult) {
        ...
    }
}

When parsing fails, an IbanFormatException is thrown. Use the Error property on the exception to check what type of error occurred.

TryParse

Alternatively to parse an IBAN without throwing an exception, use TryParse.

IIbanParser parser = new IbanParser(IbanRegistry.Default);
bool success = parser.TryParse("NL91 ABNA 0417 1643 00", out Iban iban);

Sanitation

  • An IBAN value does not need to be sanitized for spaces or tabs, before attempting to parse.
  • An IBAN value with mixed case can parse successfully but depends on each country its own specific rules.