用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - python代码库

身份证号码解析校验器(窗口型)

2022-01-16 作者: 尾翼稳定脱壳穿甲弹举报

[python]代码库

def sfz():        
    a4.delete(1.0, 'end')
    IDcard = a2.get()
    if len(IDcard) != 18:
        var = IDcard + "位数错误\n请重新输入!\n" 
    else:
        IDcard_add = IDcard[0:6]     
        IDcard_birth = IDcard[6:14] 
        IDcard_sex = IDcard[14:17]  

        area = {"11": "北京", "12": "天津", "13": "河北", "14": "山西", "15": "内蒙古", "21": "辽宁",
                "22": "吉林", "23": "黑龙江", "31": "上海", "32": "江苏", "33": "浙江", "34": "安徽",
                "35": "福建", "36": "江西", "37": "山东", "41": "河南", "42": "湖北","43": "湖南",
                "44": "广东", "45": "广西", "46": "海南", "50": "重庆", "51": "四川", "52": "贵州",
                "53": "云南", "54": "西藏", "61": "陕西", "62": "甘肃", "63": "青海", "64": "宁夏",
                "65": "新疆", "71": "台湾", "81": "香港", "82": "澳门", "91": "国外"}

        if IDcard[0:2] not in area.keys():
            var = IDcard + '\n地区非法或含有非法字符!'
        else:
            year = IDcard_birth[0:4]  
            month = IDcard_birth[4:6]  
            day = IDcard_birth[6:8]    

            if (int(year) % 4 == 0 or (int(year) % 100 == 0 and int(year) % 4 == 0)):
                ereg = re.compile('[1-9][0-9]{5}((19[0-9]{2})|(20[0-1][0-8]))((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]'
                                  '|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))'
                                  '[0-9]{3}[0-9Xx]$')      
            else:
                ereg = re.compile('[1-9][0-9]{5}((19[0-9]{2})|(20[0-1][0-8]))((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]'
                                  '|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8])'
                                  ')[0-9]{3}[0-9Xx]$')      
         
            if (re.match(ereg, IDcard)):
                IDcard_check = IDcard[17]  
                W = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]  
                IDcard_CHECK = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'] 
                IDcard_sum = 0                                             
                for i in range(0, 17):
                    IDcard_sum = IDcard_sum + int(IDcard[i]) * W[i]        
                IDcard_Check = IDcard_sum % 11 
                if IDcard_check != IDcard_CHECK[IDcard_Check]:             
                    var = IDcard + '\n身份证号码校验错误!'
                else:
                    if int(IDcard_sex) % 2 == 0:
                        var =  IDcard + '\n地区:' + area[IDcard[0: 2]] + \
                              '\n生日:' + year + '年' + month + '月' + day + '日' + "\n 性别:女\n"
                    else:

                        var = IDcard + '\n地区:' + area[IDcard[0: 2]] + \
                              "\n生日: " + year + '年' + month + '月' + day + '日' + "\n性别:男 \n"
            else:
                var = IDcard + '\n出生日期超出范围或含有非法字符!'
    a4.insert('insert', var)      
    a2.delete(0, 'end')
    
from tkinter  import *

w =Tk()
w.title('身份证号码解析校验器')
w.geometry('420x200')

a1= Label(w, text='输入身份证号码:',\
              font=('宋体', 11),\
              width=14)

a2= Entry(w,bg='white',\
        fg='black',\
        font=('仿宋',14),\
        width=18)

a3= Button(w, text='确定',\
               width=12,\
               command = sfz)

a4= Text(w, font=('宋体', 11),\
            width=14,\
            height=8)

a1.grid(column=1,row=1)
a2.grid(column=2,row=1)
a3.grid(column=2,row=2)
a4.grid(column=2,row=3)#作者:尾翼稳定脱壳穿甲弹




[代码运行效果截图]


身份证号码解析校验器(窗口型)


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...