Skip to content

Commit 5dc518e

Browse files
投稿: 身份证核验 — by 霞飞路
1 parent c8a1831 commit 5dc518e

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

script_library/index.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 1,
3-
"data_version": 88,
4-
"updated": "2026-04-11T21:12:50.787Z",
3+
"data_version": 89,
4+
"updated": "2026-04-12T05:10:38Z",
55
"announcement": null,
66
"categories": [
77
{
@@ -1490,6 +1490,30 @@
14901490
"updated": null,
14911491
"status": "active",
14921492
"lines": 236
1493+
},
1494+
{
1495+
"id": "community_身份证核验__by_霞飞路",
1496+
"name": "身份证核验 — by 霞飞路",
1497+
"name_en": "身份证核验 — by 霞飞路",
1498+
"desc": "[投稿] 身份证核验 — by 霞飞路",
1499+
"desc_en": "[投稿] 身份证核验 — by 霞飞路",
1500+
"category": "basic",
1501+
"file": "scripts/basic/script_mnul4nuo.py",
1502+
"thumbnail": null,
1503+
"version": 1,
1504+
"file_type": "py",
1505+
"author": "社区投稿",
1506+
"author_en": "社区投稿",
1507+
"tags": [
1508+
"community",
1509+
"basic"
1510+
],
1511+
"requires": [],
1512+
"min_app_version": "1.5.0",
1513+
"added": "2026-04-12",
1514+
"updated": null,
1515+
"status": "active",
1516+
"lines": 17
14931517
}
14941518
]
14951519
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import re
2+
def check_id_card(id_str):
3+
if len(id_str) != 18 : return False
4+
last = id_str[17].upper()
5+
if not (last.isdigit() or last == 'X') : return False
6+
try:
7+
if not re.search(r"^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$",id_str).group():pass
8+
except:
9+
return False
10+
weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
11+
codes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
12+
total = sum(int(id_str[i]) * weights[i] for i in range(17))
13+
mod = total % 11
14+
expected = codes[mod]
15+
return last == expected
16+
if __name__ == "__main__":
17+
print(check_id_card(input("输入18位完整sfz号码:")))

0 commit comments

Comments
 (0)