-
-
Save sgtrusty/6ec0e65bd52871b33eeb73b1a03de3b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
# Estas cedulas fueron emitidas por la JCE, pero no cumplen con el | |
# digito verificador, por lo cual deben ser verificadas por separado. | |
excepcionesCedulas = ['00000000018', '11111111123', '00100759932', '00105606543', '00114272360', '00200123640', | |
'00200409772', '00800106971', '01200004166', '01400074875', '01400000282', '03103749672', | |
'03200066940', '03800032522', '03900192284', '04900026260', '05900072869', '07700009346', | |
'00114532330', '03121982479', '40200700675', '40200639953', '00121581750', '00119161853', | |
'22321581834', '00121581800', '09421581768', '22721581818', '90001200901', '00301200901', | |
'40200452735', '40200401324', '10621581792']; | |
def is_identificacion(value): | |
""" | |
Valida las identificaciones fiscales de la República Dominicana | |
Cédula de identidad personal y Registro nacional del contribuyente | |
:param value: recibe una cédula o RNC | |
""" | |
num = map(int, value) # convierte string en lista de string | |
if len(value) == 9 or len(value) == 11: # Valida logitud | |
if value.isdigit(): # Valida que solo sean numeros | |
if len(value) == 11: # si tiene 11 digitos es una cedula | |
if value in excepcionesCedulas: # valida en el listado | |
return True | |
else: # valida el algoritmo de (LUHN) | |
return sum(num[::-2] + map(lambda x:x*2,num[-2::-2])) % 10 == 0 | |
else: # si tiene 9 digitos es un RNC | |
pesoRNC = [7, 9, 8, 6, 5, 4, 3, 2] # Mod11 pero el RNC utiliza su propio sistema de peso. | |
11 - sum(map(operator.mul,num[:-1],pesoRNC)) % 11 == num[8] | |
else: | |
return False | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment