7

I have the german "Bankleitzahl" and the account number, now I would like to calculate the corresponding IBAN with javascript, so I don't have to enter my banking-data on an untrustworthy website.

How would I calculate this with javascript on my own client?

rubo77
  • 19,527
  • 31
  • 134
  • 226
  • 1
    What do you mean by "calculating an IBAN" ? – fvu Jun 19 '13 at 17:12
  • One usually "converts" something to IBAN, but not "calculates" it. Do you want to convert it? What is the input format? – Ivan Kuckir Jun 19 '13 at 17:13
  • @fvu check this http://www.westpac.com.au/faq/iban-number/ – ebram khalil Jun 19 '13 at 17:14
  • 1
    Check the [wikipedia page](http://en.wikipedia.org/wiki/International_Bank_Account_Number) "generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account" There is a table of country formats towards the end. – Xotic750 Jun 19 '13 at 17:19
  • @ebramtharwat They explain how to transfer money internationally without using an IBAN, but the SWIFT code and their proprietary . An IBAN is a standardized bank account id given to you by your bank and based on several components as explained [here](http://en.wikipedia.org/wiki/IBAN), not more than that... – fvu Jun 19 '13 at 17:19
  • Not sure why you need this, but people at http://security.stackexchange.com/ will frown upon many suggestions. If I need to disclose sensitive information, such as bank sort code and bank account number, I would only do this offline in my bank. What makes you think that the Javascript code would even be enabled in the user's browser. What makes you think that the web site won't be hacked and the Javascript file won't be tampered with? You shouldn't make such suggestions. If you need an IBAN from the user, request it. If the user doesn't know it, ask him/her to pay a visit to the bank. – oleksii Jun 19 '13 at 17:24
  • that is exactly why I think a javascript solution is more secure than a lot of CGI converters like http://www.iban-rechner.de/ - if it is javascript only, you do not disclose your account information to the hoster, because it is calculated locally on your computer – rubo77 Jun 19 '13 at 17:33
  • @oleksii he already has the blz, he already has the acct number, ie he has all the traditional (pre IBAN) components that make up the number, for all we know he's just looking for a way to make his users' life easier by allowing to input the "old way". – fvu Jun 19 '13 at 17:33
  • Try this http://stackoverflow.com/questions/21735674/iban-validation-jquery – Srinivasan D Feb 12 '14 at 17:57

4 Answers4

7

I have found a project in github https://github.com/arhs/iban.js that make checking of IBAN a very easy stuff.

Is something like:

<script src="iban.js"></script>
<script>
    // the API is now accessible from the window.IBAN global object
    IBAN.isValid('hello world'); // false
    IBAN.isValid('BE68539007547034'); // true
</script>

Is licensed under the MIT license so you can check how it do the validation and try to use it to generate your IBAN.

PhoneixS
  • 10,574
  • 6
  • 57
  • 73
3

So, if you want to reconstruct the IBAN code using the different old-style national components at hand, you can use the Wikipedia article as a base. Specifically, a german IBAN is built up as follows:

DEkk bbbb bbbb cccc cccc cc

where

  • kk is the check code
  • bbbbbbbb is the BLZ
  • cccccccccc is the account number

Note: the exact format is country-dependent, the example above is for Germany

Tom's Cafe offers a full JavasScript implementation you can use in your own application, because the check sum calculation is not trivial.

fvu
  • 32,488
  • 6
  • 61
  • 79
3

Based on the work of http://toms-cafe.de/iban/iban.js I have developed my version of IBAN check.

You can modify the country support by modifying the variable CODE_LENGTHS

Here is my implementation:

function alertValidIBAN(iban) {
    alert(isValidIBANNumber(iban));
}
/*
 * Returns 1 if the IBAN is valid 
 * Returns 0 if the IBAN's length is not as should be (for CY the IBAN Should be 28 chars long starting with CY )
 * Returns any other number (checksum) when the IBAN is invalid (check digits do not match)
 */
function isValidIBANNumber(input) {
    var CODE_LENGTHS = {
        AD: 24, AE: 23, AT: 20, AZ: 28, BA: 20, BE: 16, BG: 22, BH: 22, BR: 29,
        CH: 21, CR: 21, CY: 28, CZ: 24, DE: 22, DK: 18, DO: 28, EE: 20, ES: 24,
        FI: 18, FO: 18, FR: 27, GB: 22, GI: 23, GL: 18, GR: 27, GT: 28, HR: 21,
        HU: 28, IE: 22, IL: 23, IS: 26, IT: 27, JO: 30, KW: 30, KZ: 20, LB: 28,
        LI: 21, LT: 20, LU: 20, LV: 21, MC: 27, MD: 24, ME: 22, MK: 19, MR: 27,
        MT: 31, MU: 30, NL: 18, NO: 15, PK: 24, PL: 28, PS: 29, PT: 25, QA: 29,
        RO: 24, RS: 22, SA: 24, SE: 24, SI: 19, SK: 24, SM: 27, TN: 24, TR: 26
    };
    var iban = String(input).toUpperCase().replace(/[^A-Z0-9]/g, ''), // keep only alphanumeric characters
            code = iban.match(/^([A-Z]{2})(\d{2})([A-Z\d]+)$/), // match and capture (1) the country code, (2) the check digits, and (3) the rest
            digits;
    // check syntax and length
    if (!code || iban.length !== CODE_LENGTHS[code[1]]) {
        return false;
    }
    // rearrange country code and check digits, and convert chars to ints
    digits = (code[3] + code[1] + code[2]).replace(/[A-Z]/g, function (letter) {
        return letter.charCodeAt(0) - 55;
    });
    // final check
    return mod97(digits);
}
function mod97(string) {
    var checksum = string.slice(0, 2), fragment;
    for (var offset = 2; offset < string.length; offset += 7) {
        fragment = String(checksum) + string.substring(offset, offset + 7);
        checksum = parseInt(fragment, 10) % 97;
    }
    return checksum;
}

Here is also a working fiddle

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
0

i think you need first to know or understand how it calculate it. i mean know what meth equation to do the calculations, however quick search on Google give me that:

i know they are not javascript as you want but you can check them and try to figure it's calculation(they are open source and free) and maybe then you can do your own JS library for it and later people ask you to help them

IBAN Verification in C#, Excel Automation Add-in, Word SmartTag

Node.js IBAN Check Service

c_iban

ebram khalil
  • 8,252
  • 7
  • 42
  • 60