python验证身份证


_natual_id_weight = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)

def
_is_natural_id_valid(oid: str) -> bool: if not isinstance(oid, str) or len(oid) != 18 or not oid[:-1].isdigit(): return False s = sum(int(d) * _natual_id_weight[i] for i, d in enumerate(oid[:-1])) result = (12 - s % 11) % 11 if result == 10: return oid[-1] == 'X' else: return oid[-1] == str(result)

 

posted on 2020-04-10 15:37  不要挡着我晒太阳  阅读(603)  评论(0编辑  收藏  举报

导航