Skip to content

Latest commit

 

History

History
76 lines (55 loc) · 2.61 KB

README.md

File metadata and controls

76 lines (55 loc) · 2.61 KB

SwedishBankAccounts

.NET Core Tests NuGet Downloads

Info

Validate Swedish Bank Account numbers, PlusGiro and BankGiro. The account numbers are validated with checksum calculations.

Based on

bankernaskontonummeruppbyggnad_anvandarmanual_sv.pdf (2024-02-22)

11-modul.pdf

10-modul.pdf

Usage

Instantiate the BankAccount, PlusGiro or BankGiro class and check the IsValid property of the object. If the account is not valid, check the ValidationResult property for details.

Examples

Bank account

var account = new BankAccount(clearigNumber, accountNumber);

if (!account.IsValid)
{
    Console.WriteLine("Account number invalid");
    Console.WriteLine($"Reason: {account.ValidationResult.ToString()}");
    return;
}

Console.WriteLine("Account number valid");
Console.WriteLine($"Validation result: {account.ValidationResult.ToString()}");
Console.WriteLine($"Bank: {account.BankName}");
Console.WriteLine($"Clearing number: {account.ClearingNumber}");
Console.WriteLine($"Account number:  {account.AccountNumber}");

The BankAccount class can be instantiated with full account number (clearing number and account number combined), but the parsing could be wrong for Swedbank accounts starting with an 8 if the clearing number has 5 digits. If possible, use the above constructor.

var account = new BankAccount(fullAccountNumber);

PlusGiro

var account = new PlusGiro(accountNumber);

if (!account.IsValid)
{
    Console.WriteLine("Account number invalid");
    Console.WriteLine($"Reason: {account.ValidationResult.ToString()}");
    return;
}

Console.WriteLine("Account number valid");
Console.WriteLine($"Validation result: {account.ValidationResult.ToString()}");

BankGiro

var account = new BankGiro(accountNumber);

if (!account.IsValid)
{
    Console.WriteLine("Account number invalid");
    Console.WriteLine($"Reason: {account.ValidationResult.ToString()}");
    return;
}

Console.WriteLine("Account number valid");
Console.WriteLine($"Validation result: {account.ValidationResult.ToString()}");