Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
xyxBooking-weapp
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2026-01-20 16:04:50 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
300af002a1c62100a1ba766c7cd663181c42603b
300af002
1 parent
39fc3c7d
fix: 增强身份证号码校验逻辑
添加完整的身份证校验规则,包括: 1. 基础格式校验 2. 地区码校验 3. 出生日期有效性检查 4. 校验码计算验证
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
3 deletions
src/pages/addVisitor/index.vue
src/pages/addVisitor/index.vue
View file @
300af00
<!--
* @Date: 2024-01-15 16:35:10
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-
08 20:35:57
* @LastEditTime: 2026-01-
20 16:04:01
* @FilePath: /xyxBooking-weapp/src/pages/addVisitor/index.vue
* @Description: 添加参观者
-->
...
...
@@ -88,8 +88,60 @@ const on_id_type_confirm = ({ selectedValue }) => {
// 身份证校验
const checkIDCard = (idcode) => {
// 简单校验
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idcode);
// 1. 基础格式校验 (18位)
if (!idcode || !/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(idcode)) {
return false;
}
// 2. 地区码校验
const cityMap = {
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 (!cityMap[idcode.substr(0, 2)]) {
return false;
}
// 3. 出生日期校验
const birthday = idcode.substr(6, 8);
const year = parseInt(birthday.substr(0, 4));
const month = parseInt(birthday.substr(4, 2));
const day = parseInt(birthday.substr(6, 2));
const date = new Date(year, month - 1, day);
if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) {
return false;
}
// 校验日期不能超过当前时间
if (date > new Date()) {
return false;
}
// 4. 校验码计算
// 加权因子
const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
// 校验位对应值
const parity = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
let sum = 0;
const codeArr = idcode.split("");
// 计算加权和
for (let i = 0; i < 17; i++) {
sum += codeArr[i] * factor[i];
}
// 取模
const mod = sum % 11;
// 获取校验位
const last = parity[mod];
// 对比最后一位 (统一转大写比较)
return last === codeArr[17].toUpperCase();
}
const save = async () => {
...
...
Please
register
or
login
to post a comment