Validate Swedish Bank Account numbers, PlusGiro and BankGiro. The account numbers are validated with checksum calculations.
bankernaskontonummeruppbyggnad_anvandarmanual_sv.pdf (2024-02-22)
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.
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);
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()}");
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()}");