Skip to content

Instantly share code, notes, and snippets.

@RicardoACS
Created June 19, 2015 23:14
Show Gist options
  • Save RicardoACS/4c0507daf2cbea723d3a to your computer and use it in GitHub Desktop.
Save RicardoACS/4c0507daf2cbea723d3a to your computer and use it in GitHub Desktop.
Validar Rut Chile
public bool validarRut(string rut ) {
bool validacion = false;
try
{
rut = rut.ToUpper();
rut = rut.Replace(".", "");
rut = rut.Replace("-", "");
int rutAux = int.Parse(rut.Substring(0, rut.Length - 1));
char dv = char.Parse(rut.Substring(rut.Length - 1, 1));
int m = 0, s = 1;
for (; rutAux != 0; rutAux /= 10) {
s = (s + rutAux % 10 * (9 - m++ % 6)) % 11;
}
if (dv == (char) (s != 0 ? s + 47 : 75)) {
validacion = true;
}
}
catch (Exception)
{
}
return validacion;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment