Ir al contenido principal

Entradas

Mostrando entradas de 2019

Validador de DPI / CUI en C#

Este método valida un número de CUI / DPI de Guatemala. Se basa en la implementación Java del siguiente blog http://xcodegt.blogspot.com/2016/09/funcion-para-validar-cui-guatemala-con.html Se actualizó el dato del número de municipios por departamento, ya que ha variado desde 2016 (fecha del post original) a la fecha. 1: private static bool ValidarDPI(string dpi) 2: { 3: var regex = "^[0-9]{4}-[0-9]{5}-[0-9]{4}$"; 4: var test = Regex.IsMatch(dpi, regex); 5: 6: if (!test) 7: { 8: return false; 9: } 10: 11: var cui = dpi.Replace("-", ""); 12: 13: var numero = cui.Substring(0, 8); 14: 15: 16: var depto = Convert.ToInt32(cui.Substring(9, 2)); 17: var muni = Convert.ToInt32(cui.Substring(11, 2)); 18: 19: var validador = Convert.ToInt32(cui.Substring(8, 1)); 20: 21: // Conteo de municipios por departamento 22: int[] munisPorDepto = 23: { 24: ...