Created
August 5, 2019 22:55
-
-
Save elton182/f7ac5fe480ad8d6ca356aa0700a59b47 to your computer and use it in GitHub Desktop.
Validação Digito Conta Corrente Santander
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
var agencia = '0189' | |
var conta = '01017417' | |
var dig = 9 | |
var retorno = validaSantander(agencia,conta,dig); | |
console.log(retorno); | |
function validaSantander(agencia, conta, digito){ | |
var texto = agencia + '00' + conta; | |
var texto = texto.split(''); | |
var multplicadores = ['9','7','3','1','0','0','9','7','1','3','1','9','7','3']; | |
var total = 0; | |
console.log(texto) | |
for(var i = 0;i < texto.length; i++){ | |
multplicadores[i] = texto[i] * multplicadores[i] | |
if( multplicadores[i] > 9){ | |
multplicadores[i] = parseInt(multplicadores[i].toString().substring(1)) | |
} | |
total += multplicadores[i] | |
} | |
console.log(multplicadores, total) | |
if( total > 9){ | |
total = parseInt(total.toString().substring(1)) | |
} | |
total = 10 - total | |
return total == digito | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Com o php segue melhorias:
/**
$numero = {AGENCIA},{CONTA}
*/
function validarContaSantander($numero_agencia,$numero_conta){
$numero = preg_replace('/[^0-9]/','',$numero_agencia);
$numero .= str_pad($numero_conta,10,"0",STR_PAD_LEFT);
// dd($numero);
// $sMult = "9731";
// $completaZeros = 10 - strlen($numero_conta);
// for($i = 0; $i <= $completaZeros; $i++){
// $sMult .= "0";
// }
// $sMult .= "97131973";
$multiplicadores = ['9','7','3','1','0','0','9','7','1','3','1','9','7','3'];
// $multiplicadores = str_split((string)$sMult);
$total = 0;
foreach(str_split((string)$numero) as $k => $n){
$multiplicadores[$k] = $n * $multiplicadores[$k];
if($multiplicadores[$k] > 9){
$multiplicadores[$k] = substr($multiplicadores[$k],1);
}
$total += (int)$multiplicadores[$k];
}
if($total > 9){
$total = substr($total,1);
}
return 10 - $total;
}