Skip to content

Instantly share code, notes, and snippets.

@bran921007
Created October 28, 2014 02:44
Show Gist options
  • Save bran921007/e6a2ee837e548a38a3d2 to your computer and use it in GitHub Desktop.
Save bran921007/e6a2ee837e548a38a3d2 to your computer and use it in GitHub Desktop.
validar cedula javascript
function validarCedula(cedula){
var Cedula = cedula;
var Verificador = Cedula.substr(-1,1);
Cedula = Cedula.substr(0,10);
var suma = 0;
for (i=0;i<Cedula.length;i++){
mod = "";
if((i % 2) == 0){mod = 1} else {mod = 2}
res = Cedula.substr(i,1) * mod;
if (res > 9){
res = res.toString();
uno = res.substr(0,1);
dos = res.substr(1,1);
res = eval(uno) + eval(dos);
}
suma += eval(res);
}
el_numero = (10 - (suma % 10)) % 10;
if (el_numero == Verificador && Cedula != "000"){
return true
}else{
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment