ibantools-germany
Version:
IBAN Validator and Generator for German Bank Accounts
33 lines (32 loc) • 1.18 kB
JavaScript
;
/**
* ibantools-germany
* Copyright (c) 2022-2026 Markus Baumer <markus@baumer.dev>
* SPDX-License-Identifier: MIT OR MPL-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
const helper_1 = require("../helper");
const method76Core = (number) => {
const digits = (0, helper_1.getDigits)(number.slice(1, 8));
const givenCheckDigit = digits.pop();
const weightedDigits = (0, helper_1.weightDigitsRTL)(digits, [2, 3, 4, 5, 6, 7]);
const sum = (0, helper_1.calculateSum)(weightedDigits);
const calculatedCheckDigit = sum % 11;
if (calculatedCheckDigit === givenCheckDigit) {
return "VALID";
}
return "INVALID";
};
exports.default = (number) => {
const paddedNumber = (0, helper_1.paddedAccountNumber)(number);
// Account type (first digit) must be 0, 4 or 6-9
if (!paddedNumber.match(/^[046789]/)) {
return "INVALID";
}
if (method76Core(paddedNumber) === "VALID") {
return "VALID";
}
// If validation fails, try checking it with trailing
// subaccount number 00 which is allowed to be omitted.
return method76Core(`${number}00`.padStart(10, "0"));
};