2021-06-15 00:49:18 -07:00
---
id: 5a23c84252665b21eecc7eaf
title: IBAN
challengeType: 5
forumTopicId: 302289
dashedName: iban
---
# --description--
2022-02-18 00:29:34 +05:30
Il numero internazione del conto bancario ([International Bank Account Number IBAN) ](https://en.wikipedia.org/wiki/International_Bank_Account_Number ) è un modo per identificare internazionalmente i conti bancari con un rischio ridotto di propagare [errori di trascrizione ](https://en.wikipedia.org/wiki/Transcription_error ).
2021-06-15 00:49:18 -07:00
2022-02-18 00:29:34 +05:30
L’ IBAN è costituito da un massimo di 34 caratteri alfanumerici:
2021-06-15 00:49:18 -07:00
< ul >
2022-02-18 00:29:34 +05:30
< li > inizia con il codice paese a due lettere ISO 3166-1 alpha-2< / li >
< li > poi due cifre di controllo, e< / li >
< li > infine un numero di conto bancario di base specifico per paese (BBAN).< / li >
2021-06-15 00:49:18 -07:00
< / ul >
2022-02-18 00:29:34 +05:30
Le cifre di controllo consentono un controllo di sanità del numero di conto bancario per confermare la sua integrità anche prima di inviare una transazione.
2021-06-15 00:49:18 -07:00
# --instructions--
2022-02-18 00:29:34 +05:30
Scrivi una funzione che prende come parametro la stringa IBAN. Se è valido restituisci true. Altrimenti, restituisci false.
2021-06-15 00:49:18 -07:00
# --hints--
2022-02-18 00:29:34 +05:30
`isValid` dovrebbe essere una funzione.
2021-06-15 00:49:18 -07:00
```js
assert(typeof isValid == 'function');
```
2022-02-18 00:29:34 +05:30
`isValid("GB82 WEST 1234 5698 7654 32")` dovrebbe restituire un booleano.
2021-06-15 00:49:18 -07:00
```js
assert(typeof isValid('GB82 WEST 1234 5698 7654 32') == 'boolean');
```
2022-02-18 00:29:34 +05:30
`isValid("GB82 WEST 1234 5698 7654 32")` dovrebbe restituire `true` .
2021-06-15 00:49:18 -07:00
```js
assert.equal(isValid('GB82 WEST 1234 5698 7654 32'), true);
```
2022-02-18 00:29:34 +05:30
`isValid("GB82 WEST 1.34 5698 7654 32")` dovrebbe restituire `false` .
2021-06-15 00:49:18 -07:00
```js
assert.equal(isValid('GB82 WEST 1.34 5698 7654 32'), false);
```
2022-02-18 00:29:34 +05:30
`isValid("GB82 WEST 1234 5698 7654 325")` dovrebbe restituire `false` .
2021-06-15 00:49:18 -07:00
```js
assert.equal(isValid('GB82 WEST 1234 5698 7654 325'), false);
```
2022-02-18 00:29:34 +05:30
`isValid("GB82 TEST 1234 5698 7654 32")` dovrebbe restituire `false` .
2021-06-15 00:49:18 -07:00
```js
assert.equal(isValid('GB82 TEST 1234 5698 7654 32'), false);
```
2022-02-18 00:29:34 +05:30
`isValid("SA03 8000 0000 6080 1016 7519")` dovrebbe restituire `true` .
2021-06-15 00:49:18 -07:00
```js
assert.equal(isValid('SA03 8000 0000 6080 1016 7519'), true);
```
# --seed--
## --seed-contents--
```js
function isValid(iban) {
}
```
# --solutions--
```js
function isValid(iban) {
var ibanLen = {
NO:15, BE:16, DK:18, FI:18, FO:18, GL:18, NL:18, MK:19,
SI:19, AT:20, BA:20, EE:20, KZ:20, LT:20, LU:20, CR:21,
CH:21, HR:21, LI:21, LV:21, BG:22, BH:22, DE:22, GB:22,
GE:22, IE:22, ME:22, RS:22, AE:23, GI:23, IL:23, AD:24,
CZ:24, ES:24, MD:24, PK:24, RO:24, SA:24, SE:24, SK:24,
VG:24, TN:24, PT:25, IS:26, TR:26, FR:27, GR:27, IT:27,
MC:27, MR:27, SM:27, AL:28, AZ:28, CY:28, DO:28, GT:28,
HU:28, LB:28, PL:28, BR:29, PS:29, KW:30, MU:30, MT:31
}
iban = __helpers.removeWhiteSpace(iban)
if (!iban.match(/^[\dA-Z]+$/)) return false
var len = iban.length
if (len != ibanLen[iban.substr(0,2)]) return false
iban = iban.substr(4) + iban.substr(0,4)
for (var s='', i=0; i< len ; i + = 1 ) s + = parseInt ( iban . charAt ( i ) , 36 )
for (var m=s.substr(0,15)%97, s=s.substr(15); s; s=s.substr(13)) m=(m+s.substr(0,13))%97
return m == 1
}
```