Skip to content

Instantly share code, notes, and snippets.

@AngelAlexQC
Created January 18, 2021 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngelAlexQC/a8150c572c1a9345d36e7054413356aa to your computer and use it in GitHub Desktop.
Save AngelAlexQC/a8150c572c1a9345d36e7054413356aa to your computer and use it in GitHub Desktop.
Validar Cédula "Ecuador"
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