Created
October 25, 2019 14:41
Star
You must be signed in to star a gist
Calcul clé rib javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fonction de calcul de la clé RIB en javascript | |
function cle_rib(code_banque, code_guichet, numero_compte){ | |
var mapping = ["", "AJ", "BKS", "CLT", "DMU", "ENV", "FOW", "GPX", "HQY", "IRZ"]; | |
var cherche_lettre = new RegExp(/[A-Z]/g); | |
var res = numero_compte.match(cherche_lettre); | |
if(res.length > 0){ | |
res.forEach(function(ch){ | |
mapping.forEach(function(str, i){ | |
if(str.includes(ch)){ | |
numero_compte = numero_compte.replace(new RegExp(ch,"g"), i); | |
return; | |
} | |
}); | |
}); | |
} | |
return (97 - ((89 * parseInt(code_banque) + 15 * parseInt(code_guichet) + 76 * parseInt(numero_compte.substring(0,6)) + 3 * parseInt(numero_compte.substring(6))) % 97)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment