Calculate european iban with javascript

I have a German "Bankleitzahl" and an account number, now I would like to calculate the corresponding IBAN using javascript, so I do not need to enter my bank account information on an unreliable website.

How can I calculate this using javascript on my own client?

+4
source share
5 answers

I found a project on github https://github.com/arhs/iban.js that makes IBAN validation very easy.

Sort of:

<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> 

It is licensed under the MIT license, so you can check how it performs validation and try to use it to generate your IBAN.

+5
source

So, if you want to restore IBAN code using different national components of the old style, you can use the Wikipedia article as a basis. In particular, the German IBAN is created as follows:

 DEkk bbbb bbbb cccc cccc cc 

Where

  • kk is a control code
  • bbbbbbbbb is BLZ
  • cccccccccc - account number

Note: the exact format varies by country, example above for Germany

Tom Cafe offers a full implementation of JavasScript , you can use it in your own application, since checking the checksum is not trivial.

+3
source

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

You can change country support by changing the CODE_LENGTHS variable

Here is my implementation:

 function alertValidIBAN(iban) { alert(isValidIBANNumber(iban)); } /* * Returns 1 if the IBAN is valid * Returns 0 if the IBAN 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(/^([AZ]{2})(\d{2})([AZ\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(/[AZ]/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; } 

Fiddle also works here

+2
source

I think you need to first find out or understand how it calculates it. I mean, I know what equation to calculate the calculations, however a quick Google search gives me the following:

I know that they are not javascript as you want, but you can check them and try to calculate its calculations (they are open source and free), and maybe then you can make your own JS library for it, and later people will ask you to help them

IBAN Validation in C #, Excel Add-in, Word SmartTag

Node.js IBAN Validation Service

c_iban

0
source

Try it,

https://stackoverflow.com/questions/21735674/iban-validation-jquery

This will evaluate the IBAN on the client side.

 for jsfiddle output: 

http://jsfiddle.net/tamilpesu_net/LyuJ6/

0
source

Source: https://habr.com/ru/post/1487100/


All Articles