身份证校验规则问题

This commit is contained in:
曹前明 2022-09-24 19:50:48 +08:00
parent 697e50b520
commit 862210f8d3
1 changed files with 7 additions and 6 deletions

View File

@ -116,9 +116,10 @@ def check_id_number(idcard):
idcard = str(idcard) idcard = str(idcard)
idcard = idcard.strip() idcard = idcard.strip()
idcard_list = list(idcard) idcard_list = list(idcard)
# 地区校验 # 地区校验
# if not area[(idcard)[0:2]]: if str(idcard[0:2]) not in area:
# return False, Errors[4] return False, Errors[3]
# 15位身份号码检测 # 15位身份号码检测
if len(idcard) == 15: if len(idcard) == 15:
@ -132,7 +133,7 @@ def check_id_number(idcard):
if re.match(ereg, idcard): if re.match(ereg, idcard):
return True, '' return True, ''
else: else:
return False, Errors[2] return False, Errors[1]
# 18位身份号码检测 # 18位身份号码检测
elif len(idcard) == 18: elif len(idcard) == 18:
# 出生日期的合法性检查 # 出生日期的合法性检查
@ -162,12 +163,12 @@ def check_id_number(idcard):
M = JYM[Y] # 判断校验位 M = JYM[Y] # 判断校验位
if M == idcard_list[17]: # 检测ID的校验位 if M == idcard_list[17]: # 检测ID的校验位
return True, '' return True, ''
else:
return False, Errors[3]
else: else:
return False, Errors[2] return False, Errors[2]
else: else:
return False, Errors[1] return False, Errors[1]
else:
return False, Errors[0]
def check_phone_e(phone): def check_phone_e(phone):