baja-lite 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/validate.js +23 -21
package/package.json
CHANGED
package/validate.js
CHANGED
|
@@ -308,30 +308,32 @@ export class ValidateItem {
|
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
async mkIdCard() {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
else if (regex18.test(value)) {
|
|
321
|
-
// 18位身份证号码需要进一步校验校验位
|
|
322
|
-
const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
323
|
-
const parity = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
|
|
324
|
-
let sum = 0;
|
|
325
|
-
for (let i = 0; i < 17; i++) {
|
|
326
|
-
sum += parseInt(value[i]) * factor[i];
|
|
311
|
+
if (this.props.mkIdCard === true) {
|
|
312
|
+
// 15位身份证号码正则表达式
|
|
313
|
+
const regex15 = /^[1-9]\d{5}\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}$/;
|
|
314
|
+
// 18位身份证号码正则表达式
|
|
315
|
+
const regex18 = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[0-9Xx]$/;
|
|
316
|
+
const value = this.value;
|
|
317
|
+
// 首先检查是否符合15位或18位的正则表达式
|
|
318
|
+
if (regex15.test(value)) {
|
|
319
|
+
return;
|
|
327
320
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
321
|
+
else if (regex18.test(value)) {
|
|
322
|
+
// 18位身份证号码需要进一步校验校验位
|
|
323
|
+
const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
324
|
+
const parity = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
|
|
325
|
+
let sum = 0;
|
|
326
|
+
for (let i = 0; i < 17; i++) {
|
|
327
|
+
sum += parseInt(value[i]) * factor[i];
|
|
328
|
+
}
|
|
329
|
+
const mod = sum % 11;
|
|
330
|
+
const checkDigit = value[17].toUpperCase();
|
|
331
|
+
if (checkDigit !== parity[mod]) {
|
|
332
|
+
throw new Error('身份证号码错误');
|
|
333
|
+
}
|
|
332
334
|
}
|
|
335
|
+
throw new Error('身份证号码错误');
|
|
333
336
|
}
|
|
334
|
-
throw new Error('身份证号码错误');
|
|
335
337
|
}
|
|
336
338
|
element() {
|
|
337
339
|
return [{
|