hookehuyr

fix 身份证控件校验逻辑优化

1 <!-- 1 <!--
2 * @Date: 2022-09-14 14:44:30 2 * @Date: 2022-09-14 14:44:30
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-04-07 06:09:28 4 + * @LastEditTime: 2024-04-08 17:59:03
5 * @FilePath: /data-table/src/components/IdentityField/index.vue 5 * @FilePath: /data-table/src/components/IdentityField/index.vue
6 * @Description: 身份证输入控件 6 * @Description: 身份证输入控件
7 --> 7 -->
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
57 import $ from "jquery"; 57 import $ from "jquery";
58 import { storeToRefs, mainStore } from "@/utils/generatePackage"; 58 import { storeToRefs, mainStore } from "@/utils/generatePackage";
59 import { showSuccessToast, showFailToast } from "vant"; 59 import { showSuccessToast, showFailToast } from "vant";
60 - 60 +import idCard from "idcard";
61 61
62 const props = defineProps({ 62 const props = defineProps({
63 item: Object, 63 item: Object,
...@@ -137,7 +137,7 @@ const blurKeyboard = () => { ...@@ -137,7 +137,7 @@ const blurKeyboard = () => {
137 const input_val = props.item.value; 137 const input_val = props.item.value;
138 if (required && !input_val) { 138 if (required && !input_val) {
139 showFailToast("身份证号码不能为空"); 139 showFailToast("身份证号码不能为空");
140 - } else if (input_val && !/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(input_val)) { 140 + } else if (input_val && !idCard.verify(input_val)) {
141 showFailToast("请输入正确身份证号码"); 141 showFailToast("请输入正确身份证号码");
142 } else { 142 } else {
143 // gender.value = getGenderByIdNumber(input_val) 143 // gender.value = getGenderByIdNumber(input_val)
...@@ -150,7 +150,7 @@ const required = props.item.component_props.required; ...@@ -150,7 +150,7 @@ const required = props.item.component_props.required;
150 const validator = (val) => { 150 const validator = (val) => {
151 if (required && !val) { 151 if (required && !val) {
152 return false; 152 return false;
153 - } else if (val && !/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(val)) { 153 + } else if (val && !idCard.verify(val)) {
154 return false; 154 return false;
155 } else { 155 } else {
156 return true; 156 return true;
...@@ -160,7 +160,7 @@ const validator = (val) => { ...@@ -160,7 +160,7 @@ const validator = (val) => {
160 const validatorMessage = (val, rule) => { 160 const validatorMessage = (val, rule) => {
161 if (required && !val) { 161 if (required && !val) {
162 return "身份证号码不能为空"; 162 return "身份证号码不能为空";
163 - } else if (val && !/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(val)) { 163 + } else if (val && !idCard.verify(val)) {
164 return "请输入正确身份证号码"; 164 return "请输入正确身份证号码";
165 } 165 }
166 }; 166 };
......