Skip to main content
Inly\Core\Support\SwedishBankAccount\SwedishBankAccount is a support API for Swedish domestic bank account numbers. It validates clearing number and account number combinations against known Swedish bank rules, exposes the matched bank metadata, and returns normalized values that are safe to use in payment exports.

Overview

Use this class when you need to:
  • validate Swedish domestic bank account input
  • split a bank account into clearing number and account number
  • normalize a Swedish account into an export-ready BBAN value
  • derive a BIC code from a known clearing number
It accepts common user-facing formats such as digits-only input, spaced input, and hyphenated input.
This helper is for Swedish domestic accounts, not IBAN or Bankgiro validation. In Core, PaymentFileTemplate uses it when a payment account is a Swedish bank account rather than an IBAN or Bankgiro number.

Usage

Parsing

Use parse() when you want a valid account or an exception:
use Inly\Core\Support\SwedishBankAccount\SwedishBankAccount;

$account = SwedishBankAccount::parse('5000-1001000');

$account->bank(); // 'SEB'
$account->clearing(); // '5000'
$account->number(); // '1001000'
$account->normalizedClearing(); // '5000'
$account->normalizedBban(); // '50001001000'
$account->bic(); // 'ESSESESS'
parse() throws InvalidArgumentException when the input cannot be parsed as a valid Swedish bank account number. It accepts these input formats:
  • digits only, such as 50001001000
  • digits separated by spaces, such as 5000 1001 000
  • digits separated by hyphens, such as 5000-1001000
It does not strip arbitrary punctuation or repair malformed split data from consumer apps.

Non-Throwing Validation

Use the constructor when you want to validate input without throwing:
use Inly\Core\Support\SwedishBankAccount\SwedishBankAccount;

$account = new SwedishBankAccount('5000 1001 000');

if (! $account->isValid()) {
    // Show a validation error
}
This is useful when you only need a boolean validity check before deciding what to do next. The constructor uses the same accepted input formats as parse(), but returns an invalid instance instead of throwing when the format or bank rules do not match.

Nullable Parsing

Use tryParse() when you want the same parsing rules without exceptions:
use Inly\Core\Support\SwedishBankAccount\SwedishBankAccount;

$account = SwedishBankAccount::tryParse($input);

if ($account === null) {
    // Invalid Swedish bank account number
}

Examples

Five-Digit Sparbanken Clearing Numbers

Sparbanken-style clearing numbers may be entered with five digits. normalizedClearing() returns the export-safe four-digit clearing code, while normalizedBban() keeps the correct domestic account representation:
use Inly\Core\Support\SwedishBankAccount\SwedishBankAccount;

$account = SwedishBankAccount::parse('80001-1000000008');

$account->clearing(); // '80001'
$account->normalizedClearing(); // '8000'
$account->normalizedBban(); // '80001000000008'
$account->bic(); // 'SWEDSESS'

Payment File Usage

This is the main package use case today. PaymentFileTemplate uses the helper to validate domestic creditor accounts and derive export values:
use Inly\Core\Support\SwedishBankAccount\SwedishBankAccount;

$swedishBankAccount = SwedishBankAccount::parse($account->value);

$normalizedBban = $swedishBankAccount->normalizedBban();
$bic = $swedishBankAccount->bic();
Use normalizedBban() for the domestic account number you send in the payment file, and bic() when the receiving bank identifier is required.

Reference

Public Entry Points

MethodReturnsUse When
__construct(number)SwedishBankAccountYou want a non-throwing validation path and will check isValid() manually.
parse(number)SwedishBankAccountYou want a valid parsed account or an InvalidArgumentException.
tryParse(number)?SwedishBankAccountYou want strict parsing semantics without exceptions.

Instance Methods

MethodReturnsDescription
isValid()boolReturns whether the constructor input matched a known Swedish bank account rule.
bank()?stringReturns the matched bank name.
clearing()?stringReturns the matched clearing number.
number()?stringReturns the account digits excluding the clearing number.
normalizedClearing()stringReturns the normalized clearing number for downstream integrations.
normalizedBban()stringReturns the normalized domestic account number used in exports.
bic()stringReturns the BIC derived from the normalized clearing number.

Normalization Rules

The helper applies a few important rules:
  • It strips formatting such as spaces and hyphens from standard user input.
  • It validates against known bank-specific clearing ranges and checksum rules.
  • It normalizes five-digit clearing numbers that begin with 8 to a four-digit clearing code for export use.
  • It derives BIC values from an internal clearing-number map.
bic() throws InvalidArgumentException if the account is valid but the clearing number is not yet mapped to a BIC. Add the missing range to the helper before relying on automatic BIC resolution for that bank.

Troubleshooting

Invalid Swedish bank account number

The input did not match a known bank rule or it used an unsupported format. Try one of these approaches:
  • pass the raw domestic account value using only digits, spaces, or hyphens
  • use tryParse() if invalid input is expected
  • use the constructor plus isValid() in validation flows

Unknown Swedish clearing number

The account validated successfully, but the helper cannot derive a BIC from the current clearing-number map. Update the BIC mapping in SwedishBankAccount::bic() when Core adds support for a new clearing range.

Next Steps

  • Read Support APIs if you want to document more package helpers in Inly\Core\Support\....
  • See the payment file template implementation when you need a real package example of normalizedBban() and bic() in use.