Skip to content

IBAN

IBAN (International Bank Account Number) is the international standard for identifying bank accounts. A Polish IBAN is the two-letter country prefix PL followed by a 26-digit NRB. Validation requires the PL prefix and applies the standard MOD-97 checksum to the NRB portion.

Use Numerik::nrb() when you have a 26-digit number without the country prefix. Use Numerik::iban() when you expect the full international form.

use SlashLab\Numerik\Numerik;
// Boolean
Numerik::iban()->isValid('PL61102010260000000000000000'); // true
// Spaced format and lowercase prefix are accepted
Numerik::iban()->isValid('PL61 1020 1026 0000 0000 0000 0000'); // true
Numerik::iban()->isValid('pl61102010260000000000000000'); // true
// Bare NRB without prefix is rejected — use Numerik::nrb() for that
Numerik::iban()->isValid('61102010260000000000000000'); // false
// Rich result
$result = Numerik::iban()->validate('PL61102010260000000000000000');
$result->isValid; // true
// Parse to value object
$iban = Numerik::iban()->parse('PL61102010260000000000000000');
// Null on failure instead of exception
$iban = Numerik::iban()->tryParse('bad-input'); // null

parse() and tryParse() return a SlashLab\Numerik\ValueObjects\Iban instance.

MethodReturn typeDescription
getRaw()stringThe original input, untouched.
getNormalized()stringPL + 26 digits, e.g. PL61102010260000000000000000.
__toString()stringSame as getNormalized().
MethodReturn typeDescription
getFormatted()stringStandard grouped display: PL61 1020 1026 0000 0000 0000 0000.
MethodReturn typeDescription
getCountryCode()stringAlways PL.
getNrb()stringThe 26-digit NRB without the country prefix.
getCheckDigits()stringTwo MOD-97 check digits (positions 3–4 of the IBAN).
getSortCode()string8-digit bank sort code.
getBankCode()stringFirst 3 digits of the sort code — identifies the bank.
getAccountNumber()stringLast 16 digits — the customer account number.
$iban = Numerik::iban()->parse('PL61102010260000000000000000');
$iban->getRaw(); // 'PL61102010260000000000000000'
$iban->getNormalized(); // 'PL61102010260000000000000000'
$iban->getFormatted(); // 'PL61 1020 1026 0000 0000 0000 0000'
$iban->getCountryCode(); // 'PL'
$iban->getNrb(); // '61102010260000000000000000'
$iban->getCheckDigits(); // '61'
$iban->getSortCode(); // '10201026'
$iban->getBankCode(); // '102'
$iban->getAccountNumber(); // '0000000000000000'
// Spaced and lowercase inputs normalise to the same value
$a = Numerik::iban()->parse('PL61102010260000000000000000');
$b = Numerik::iban()->parse('PL61 1020 1026 0000 0000 0000 0000');
$c = Numerik::iban()->parse('pl61102010260000000000000000');
$a->getNormalized() === $b->getNormalized(); // true
$b->getNormalized() === $c->getNormalized(); // true
  1. Strip spaces and hyphens. Reject inputs over 40 characters.
  2. Assert the first two characters are PL (case-insensitive); fail with InvalidFormat.
  3. Strip the prefix. Assert exactly 26 digits remain; fail with InvalidLength.
  4. Apply the NRB MOD-97 checksum — see the Algorithms reference.
ReasonValueWhen
InvalidLengthinvalid_lengthNRB portion is not exactly 26 digits, or raw input exceeds 40 characters.
InvalidFormatinvalid_formatInput does not start with PL.
InvalidCharactersinvalid_charactersNRB portion contains non-digit characters.
InvalidChecksuminvalid_checksumMOD-97 remainder is not 1.
If this saved you time → ☕ Buy me a coffee