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

18Dec/092

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

miguelin
dic7
jeanfer
YuryBlack
lolplaying
carlosakita
elQuique
jmangt
freddier
jepser
guatemalajoven
vochomaster
paolamurias
espyder
rodrigopolo
SiRGt
abasme
demuxer
toigt
spam
Calizman
donttrythis
Ronald_MacKay
ykro
agdsys
damarist
BcB
katiuskaflores
mestradaa
S2RD2
tutuista
pfpaau
jesmyc
promeme
raep3153
migueldeicaza
Friends: 122 Followers: 209

Categories

Sitios amigos

Algunos Derechos Reservados

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