GeoAvila (Geovanny G. Avila) Desarrollo.. de software.

18Dec/094

Validar un NIT(Guatemala) en C#

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.

C#:
  1. public bool ValidarNIT(string Nit)
  2.         {
  3.             int pos = Nit.IndexOf("-");
  4.             string Correlativo = Nit.Substring(0, pos);
  5.             string DigitoVerificador = Nit.Substring(pos + 1);
  6.             int Factor = Correlativo.Length + 1;
  7.             int Suma = 0;
  8.             int Valor = 0;
  9.  
  10.             for (int x = 0; x <= Nit.IndexOf("-") - 1; x++)
  11.             {
  12.                 Valor = Convert.ToInt32(Nit.Substring(x, 1));
  13.                 Suma = Suma + (Valor * Factor);
  14.                 Factor = Factor - 1;
  15.             }
  16.  
  17.             double xMOd11 = 0;
  18.             xMOd11 = (11 - (Suma % 11)) % 11;
  19.             string s = Convert.ToString(xMOd11);
  20.             if ((xMOd11 == 10 & DigitoVerificador == "K") | (s == DigitoVerificador))
  21.             {
  22.                 return true;
  23.             }
  24.             return false;
  25.         }

Nos Vemos.

Sigueme en Twitter

Recent Posts

Amigos de Twitter

isagc_88
pena2
kalugt
mishu7
luismuybien
evesosa
prsarahevans
PilarPreza
valeriaau
thomas_weller
xabivargas
albertomontt
J05uE
softcarlos
Blackstare
guise
fayerwayer
ChapinGeek
yoasumo
LibrosyMasgt
jazzandblue
daniellacayo
xisaac
orlandomgj
guilleybruno
TuFrac
Luckysilva
guatecham
f0vela
barcampgt
Elultimodepaz
tuxtor
giopack
xarquis
andreimorales
robertogt
Friends: Followers:

Categories

Sitios amigos

Algunos Derechos Reservados

Blog bajo licencia Creative Commons Attribution-ShareAlike 3.0 License
Creative Commons License