Created
January 18, 2021 19:42
-
-
Save AngelAlexQC/a8150c572c1a9345d36e7054413356aa to your computer and use it in GitHub Desktop.
Validar Cédula "Ecuador"
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
export function validarCedula(cedula: string | any) { | |
let total = 0; | |
const longitud = cedula.length; | |
const longcheck = longitud - 1; | |
if (cedula !== "" && longitud === 10) { | |
for (let i = 0; i < longcheck; i++) { | |
if (i % 2 === 0) { | |
let aux = cedula.charAt(i) * 2; | |
if (aux > 9) { | |
aux -= 9; | |
} | |
total += aux; | |
} else { | |
// tslint:disable-next-line: radix | |
total += parseInt(cedula.charAt(i)); // parseInt o concatenará en lugar de sumar | |
} | |
} | |
total = total % 10 ? 10 - (total % 10) : 0; | |
// tslint:disable-next-line: triple-equals | |
if (cedula.charAt(longitud - 1) == total) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment