Skip to content

This library written in pure C# checks the validity of a Hungarian bank account number and determines which bank is belongs to.

License

Notifications You must be signed in to change notification settings

belidzs/HungarianBankAccount

Repository files navigation

HungarianBankAccount

This library written in C# checks the validity of a Hungarian bank account number (in GIRO format) and determines which bank it belongs to.

Usage

Let's check a valid bank account:

string validAccountNumber = "10032000-01076349";
var accountValid = new BankAccount(validAccountNumber);
System.Console.WriteLine($"{accountValid.AccountNumber}: IsValid = {accountValid.IsValid}, Bank = {accountValid.Bank}");

An invalid bank account will return IsValid = false and throws FormatException when Bank property is read:

var accountInvalidNumber = new BankAccount("00000000-00000000-00000001");
System.Console.WriteLine($"{accountInvalidNumber.AccountNumber}: IsValid = {accountInvalidNumber.IsValid}");
try
{
    System.Console.WriteLine($"Checking bank details for {accountInvalidNumber.AccountNumber}");
    System.Console.WriteLine(accountInvalidNumber.Bank);
}
catch (FormatException)
{
    System.Console.WriteLine($"{typeof(FormatException)} was thrown because account number was not valid");
}

When the syntax of the bank account number is correct, but it doesn't belong to any known bank KeyNotFoundException is thrown:

var accountInvalidBank = new BankAccount("00000000-00000000");
System.Console.WriteLine($"{accountInvalidBank.AccountNumber}: IsValid = {accountInvalidBank.IsValid} (it's technically valid)");
try
{
    System.Console.WriteLine($"Checking bank details for {accountInvalidBank.AccountNumber}");
    System.Console.WriteLine(accountInvalidBank.Bank);
}
catch (KeyNotFoundException)
{
    System.Console.WriteLine($"{typeof(KeyNotFoundException)} was thrown, because the bank account number doesn't belong to any known bank.");
}

Alternatively you can use the static Validator.Validate(string accountNumber) method to check if the number is syntactically and mathematically correct.

Download from Nuget

'nuget badge'

About

This library written in pure C# checks the validity of a Hungarian bank account number and determines which bank is belongs to.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages