Posts Tagged ‘C# Csharp Validar NIT Guatemala’

Validar un NIT(Guatemala) en C#

6

Esta función,  encontre esta función para validar un NIT con JavaScript, bueno pasando a C#, quedaría algo así, espero les sirva el este código.

public bool ValidarNIT(string Nit)
        {
            int pos = Nit.IndexOf("-");
            string Correlativo = Nit.Substring(0, pos);
            string DigitoVerificador = Nit.Substring(pos + 1);
            int Factor = Correlativo.Length + 1;
            int Suma = 0;
            int Valor = 0;

            for (int x = 0; x <= Nit.IndexOf("-") - 1; x++)
            {
                Valor = Convert.ToInt32(Nit.Substring(x, 1));
                Suma = Suma + (Valor * Factor);
                Factor = Factor - 1;
            }

            double xMOd11 = 0;
            xMOd11 = (11 - (Suma % 11)) % 11;
            string s = Convert.ToString(xMOd11);
            if ((xMOd11 == 10 & DigitoVerificador == "K") | (s == DigitoVerificador))
            {
                return true;
            }
            return false;
        }

Nos Vemos.


Post navigation