import re
regx = "^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9)|10|11|12))(([0-2][1-9])|10|20|30|31\d{3}[0-9Xx]$"
id = input('输入身份证号码:')
while True:
id_result = re.search(regx, id)
if id_result is None:
print('输入身份证不合法')
id = input('输入身份证号码')
else:
break
id_no = id_result.group()
year = id_no[6:10]
month = id_no[10:12]
day = id_no[12:14]
print('生日:{}年{}月{}日'.format(year, month,day))
根据身份证号 判断生日*(python)
最新推荐文章于 2024-12-25 19:11:39 发布
本文展示了如何使用Python的re模块进行身份证号码的合法性检查,并提取出生日期。通过正则表达式实现快速身份验证,适合初学者理解基础的正则用法。
1693

被折叠的 条评论
为什么被折叠?



