SwedishBankAccounts 1.1.0

dotnet add package SwedishBankAccounts --version 1.1.0
                    
NuGet\Install-Package SwedishBankAccounts -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SwedishBankAccounts" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SwedishBankAccounts" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SwedishBankAccounts" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SwedishBankAccounts --version 1.1.0
                    
#r "nuget: SwedishBankAccounts, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SwedishBankAccounts@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SwedishBankAccounts&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SwedishBankAccounts&version=1.1.0
                    
Install as a Cake Tool

GitHub Workflow Status NuGet Downloads

Swedish Bank Account for C#

This package validates and returns details about Swedish bank account numbers using C#/.NET. The details and validation rules are based on the documentation provided by Bankgirot, which can be found here.

This repository is based on swantzter/kontonummer as the foundational model, thank you!

Important Caveat

Some bank account numbers are impossible to validate (as they do not have a check digit) and are indistinguishable from validatable accounts. We recommend using this library on form input fields but do not prevent form submission if the account number is reported as invalid. A good idea would instead be a warning saying "there is a chance this is not a valid bank account number, you may want to double check."

Examples

TryParse

using SwedishBankAccounts;

class Test
{
  public void BankAccountLogic()
  {
      if(BankAccountNumber.TryParse("9553, 123 45 67", out var bankAccountNumber))
      {
          Console.Write(bankAccountNumber);              // 9553-5894364
          Console.Write(bankAccountNumber.Bank.Name);    // Avanza Bank
          Console.Write(bankAccountNumber.Bank.Bic);     // AVANSESX
      }
  }
}

Modulus Validation and Calculation

using SwedishBankAccounts;

class Test 
{
  public void ModulusValidation() 
  {
      SwedishBankAccounts.Modulus10.Validate("12556548711")     // True
      SwedishBankAccounts.Modulus10.Validate("12556548713")     // False

      SwedishBankAccounts.Modulus11.Validate("90714172383")     // True
      SwedishBankAccounts.Modulus11.Validate("90714172382")     // False
  }

  public void ModulusCalculation()
  {
      SwedishBankAccounts.Modulus10.CalculateCheckDigit("1255654871")       // Returns 1
      SwedishBankAccounts.Modulus11.CalculateCheckDigit("9071417238")       // Returns 3
  }
}

Formatting

The library supports multiple output formats for bank account numbers:

using SwedishBankAccounts;

var bankAccount = BankAccountNumber.Parse("9553-5894364");

// Default format (NUMERIC)
Console.WriteLine(bankAccount.ToString());           // 9553-5894364
Console.WriteLine(bankAccount.ToString("N"));       // 9553-5894364
Console.WriteLine(bankAccount.ToString("NUMERIC")); // 9553-5894364

// COMPACT format
Console.WriteLine(bankAccount.ToString("C"));       // 95535894364
Console.WriteLine(bankAccount.ToString("COMPACT")); // 95535894364

// SORTINGCODE format
Console.WriteLine(bankAccount.ToString("S"));           // 9553
Console.WriteLine(bankAccount.ToString("SORTINGCODE")); // 9553

// ACCOUNTNUMBER format
Console.WriteLine(bankAccount.ToString("A"));             // 5894364
Console.WriteLine(bankAccount.ToString("ACCOUNTNUMBER")); // 5894364

// IBAN format
Console.WriteLine(bankAccount.ToString("I"));    // SE8095535894364000000
Console.WriteLine(bankAccount.ToString("IBAN")); // SE8095535894364000000

// PRETTY format (with bank name)
Console.WriteLine(bankAccount.ToString("P"));      // Avanza Bank 9553-5894364
Console.WriteLine(bankAccount.ToString("PRETTY")); // Avanza Bank 9553-5894364

All format strings are case-insensitive. Invalid format strings will throw a FormatException.

Bank Information and BIC/SWIFT Codes

The Bank property provides access to full bank information including BIC/SWIFT codes:

using SwedishBankAccounts;

var bankAccount = BankAccountNumber.Parse("9553-5894364");

// Access bank information
Console.WriteLine(bankAccount.Bank.Name);                    // Avanza Bank
Console.WriteLine(bankAccount.Bank.Bic);                     // AVANSESX
Console.WriteLine(bankAccount.Bank.SortingCodeRange.Length); // 1

// Get bank information directly from Bank.Banks collection
var bank = Bank.Banks.FirstOrDefault(b => b.Name == "Swedbank");
Console.WriteLine(bank?.Bic); // SWEDSESS

// Find bank by sorting code
var sortingCode = "7000";
var swedbankAccount = Bank.Banks.FirstOrDefault(b => b.HasSortingCode(sortingCode));
Console.WriteLine(swedbankAccount?.Bic); // SWEDSESS

BIC/SWIFT codes are available for major Swedish banks including Swedbank, Nordea, SEB, Handelsbanken, Danske Bank, Avanza, and many others.

Breaking Changes in v1.0.0

Important: Starting from version 1.0.0, the Bank property returns a Bank object instead of a string:

// v0.x.x (old way)
string bankName = bankAccount.Bank;        // ❌ No longer works

// v1.0.0+ (new way)
string bankName = bankAccount.Bank.Name;   // ✅ Correct
string bic = bankAccount.Bank.Bic;         // ✅ New: Access to BIC codes
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 228 10/4/2025
1.0.0 150 10/2/2025
0.2.1 151 10/2/2025
0.2.0 153 9/28/2025
0.1.4 987 3/19/2024
0.1.3 193 10/13/2023
0.1.2 233 6/2/2023
0.1.2-alpha.0.1 163 5/30/2023
0.1.1 210 5/30/2023