当前位置:网站首页>[verification of ID number]
[verification of ID number]
2022-07-24 21:17:00 【Blogger Huashen】
【 ID number verification 】
// Verify the legitimacy of the ID card
IdentityCodeValid(code) {
var city = {
11: " Beijing ",
12: " tianjin ",
13: " hebei ",
14: " shanxi ",
15: " Inner Mongolia ",
21: " liaoning ",
22: " Ji Lin ",
23: " heilongjiang ",
31: " Shanghai ",
32: " jiangsu ",
33: " Zhejiang ",
34: " anhui ",
35: " fujian ",
36: " jiangxi ",
37: " Shandong ",
41: " Henan ",
42: " hubei ",
43: " hunan ",
44: " guangdong ",
45: " guangxi ",
46: " hainan ",
50: " Chongqing ",
51: " sichuan ",
52: " guizhou ",
53: " yunnan ",
54: " Tibet ",
61: " shaanxi ",
62: " gansu ",
63: " qinghai ",
64: " ningxia ",
65: " xinjiang ",
71: " Taiwan ",
81: " Hong Kong ",
82: " Macau ",
91: " Abroad "
};
var tip = "";
var pass = true;
if (!code || !/(^\d{15}$)|(^\d{17}(\d|X|x)$)/.test(code)) {
tip = " The ID number is wrong ";
pass = false;
} else if (!city[code.substr(0, 2)]) {
tip = " Wrong address encoding ";
pass = false;
} else {
//18 The last check digit of the ID card must be verified
if (code.length == 18) {
//∑(ai×Wi)(mod 11)
var year = code.substr(6, 4), // ID card year
month = code.substr(10, 2), // ID month
date = code.substr(12, 2), // ID card date
sexNum = code.split(14, 3), // Gender
time = Date.parse(month + '-' + date + '-' + year), // Id date and time stamp date
now_time = Date.parse(new Date()), // Current timestamp
dates = (new Date(year, month, 0)).getDate(); // Number of days of ID card in the current month
console.log(Number(year), " Get year , Control year is less than 1922 by false")
let newyear = Number(year)
if (newyear < 1922) {
pass = false;
}
// Weighting factors
code = code.split('');
var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
// Check bit
var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
var sum = 0;
var ai = 0;
var wi = 0;
for (var i = 0; i < 17; i++) {
ai = code[i];
wi = factor[i];
sum += ai * wi;
}
var last = parity[sum % 11];
if (parity[sum % 11] != code[17]) {
tip = " Check bit error ";
pass = false;
}
}
}
console.log(tip, " Wrong presentation ")
console.log(pass, " Whether it is right ")
return pass;
},
Page using
let idcar = this.IdentityCodeValid(this.information.idCard)
if (idcar == false) {
wx.showToast({
title: ' The length or format of your ID card is wrong ',
icon: 'none',
duration: 2000
})
return
}
边栏推荐
- Kubernetes resource list: how to create resources?
- [feature transformation] feature transformation is to ensure small information loss but high-quality prediction results.
- CAD sets hyperlinks to entities (WEB version)
- 92. Recursive implementation of exponential enumeration
- How to apply Po mode in selenium automated testing
- Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry
- Go language structure
- [jzof] 04 search in two-dimensional array
- Information system project manager must recite the core examination site (47) project subcontract
- Press Ctrl to pop up a dialog box. How to close this dialog box?
猜你喜欢

Evolution of network IO model

Generate self signed certificate: generate certificate and secret key

Preview and save pictures using uni app

Cloud native observability tracking technology in the eyes of Baidu engineers

whistle ERR_ CERT_ AUTHORITY_ INVALID

How to test WebService interface

Five common misuse of async/await

How to prevent weight under Gao Bingfa?

Baidu interview question - judge whether a positive integer is to the power of K of 2

Go language error handling
随机推荐
Press Ctrl to pop up a dialog box. How to close this dialog box?
Bring new people's experience
How to choose securities companies that support flush? Is it safe to open an account on your mobile phone
Scientific computing toolkit SciPy data interpolation
Summary of yarn Explorer
Static & dynamic & file address book
Mitmproxy tampering with returned data
Preview and save pictures using uni app
C # image template matching and marking
Node installation using NVM succeeded, but NPM installation failed (error while downloading, TLS handshake timeout)
ECCV 2022 open source | target segmentation for 10000 frames of video
Leetcode 15. sum of three numbers
Go language structure
Five common misuse of async/await
what? Does the multi merchant system not adapt to app? This is coming!
Eight transformation qualities that it leaders should possess
Open source demo | release of open source example of arcall applet
Spark related FAQ summary
Summary of yarn capacity scheduler
Evaluation of four operation expressions