Skip to content

Instantly share code, notes, and snippets.

@rivsc
Created October 25, 2019 14:41
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rivsc/47034610d00d612c91ebf1861959500d to your computer and use it in GitHub Desktop.
Calcul clé rib javascript
// 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