Created
October 28, 2014 02:44
-
-
Save bran921007/e6a2ee837e548a38a3d2 to your computer and use it in GitHub Desktop.
validar cedula javascript
This file contains hidden or 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
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