Skip to content

Instantly share code, notes, and snippets.

@DannyFeliz
Created July 9, 2016 23:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DannyFeliz/309daa0b1d62001c2bcb909a182fb91d to your computer and use it in GitHub Desktop.
Save DannyFeliz/309daa0b1d62001c2bcb909a182fb91d to your computer and use it in GitHub Desktop.
valida cedula
public static bool validaCedula(string pCedula)
{
int vnTotal = 0;
string vcCedula = pCedula.Replace("-", "");
int pLongCed = vcCedula.Trim().Length;
int[] digitoMult = new int[11] { 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 };
if (pLongCed < 11 || pLongCed > 11)
return false;
for (int vDig = 1; vDig <= pLongCed; vDig++)
{
int vCalculo = Int32.Parse(vcCedula.Substring(vDig - 1, 1)) * digitoMult[vDig - 1];
if (vCalculo < 10)
vnTotal += vCalculo;
else
vnTotal += Int32.Parse(vCalculo.ToString().Substring(0, 1)) + Int32.Parse(vCalculo.ToString().Substring(1, 1));
}
if (vnTotal % 10 == 0)
return true;
else
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment