Class IbanExtensions
- Namespace
- HeroKit.Banking
- Assembly
- HeroKit.dll
Contains extension methods for validating and formatting IBANs (ISO 13616).
public static class IbanExtensions
- Inheritance
-
IbanExtensions
- Inherited Members
Methods
FormatIban(string?)
Formats a valid IBAN in uppercase blocks of four characters separated by single spaces.
public static string? FormatIban(this string? value)
Parameters
valuestringThe IBAN to format. Spaces are ignored and lowercase letters are accepted.
Returns
- string
The formatted IBAN, or null if the input is not a valid IBAN.
Examples
"tr330006100519786457841326".FormatIban(); // "TR33 0006 1005 1978 6457 8413 26"
GetBank(string?)
Returns the bank of a valid IBAN from the bank directory of its country (Banks).
public static Bank? GetBank(this string? value)
Parameters
valuestringThe IBAN, with or without spaces.
Returns
- Bank
The bank, or null if the IBAN is invalid, its country has no bank directory or the bank code is unknown.
Examples
"TR33 0006 1005 1978 6457 8413 26".GetBank()?.Name; // null: bank code 00061 is not assigned
"TR78 0006 2000 0000 0006 2950 05".GetBank()?.Name; // "Türkiye Garanti Bankası A.Ş."
IsValidIban(string?)
Determines whether a string is a valid IBAN (ISO 13616). Spaces are ignored and lowercase letters are accepted.
public static bool IsValidIban(this string? value)
Parameters
valuestringThe string to check.
Returns
- bool
true if the string is a valid IBAN; otherwise, false. Null or empty input returns false.
Examples
"TR33 0006 1005 1978 6457 8413 26".IsValidIban(); // true
"TR330006100519786457841327".IsValidIban(); // false
Remarks
The check covers structure (country letters, check digits, alphanumeric BBAN, length 15 to 34) and the mod-97 checksum. For Turkey ("TR") the length must be 26 and the reserved fifth character must be '0'.
NormalizeIban(string?)
Normalizes a valid IBAN to uppercase without spaces.
public static string? NormalizeIban(this string? value)
Parameters
valuestringThe IBAN to normalize. Spaces are ignored and lowercase letters are accepted.
Returns
- string
The normalized IBAN, or null if the input is not a valid IBAN.
Examples
"tr33 0006 1005 1978 6457 8413 26".NormalizeIban(); // "TR330006100519786457841326"