Regular matching ID number

Regular match the ID number into 18 and 15
first to write regular ID number until we first understand the structure 18

地区: ([1-6][1-9]|50)\d{4}  // 补充重庆地区50
年的前两位: (18|19|20)            1800-2399
年的后两位: \d{2}
月份:((0[1-9])|10|11|12)
天数: (([0-2][1-9])|10|20|30|31)      闰年不能禁止29+
三位顺序码: \d{3}
校验码: [0-9Xx]
// 校验18位的身份证
let _IDRe18 =  /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/

ID number of the structure 15

地区:[1-6][1-9]\d{4}
年份只有后两位:\d{2}
月份:((0[1-9])|10|11|12)
天数:(([0-2][1-9])|10|20|30|31)      闰年不能禁止29+
三位顺序码: \d{3}
// 校验15位的身份证
let _IDRe15 =  /^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/

Redux: simultaneously check 18 and 15 of the ID card

let _IDRe18 = /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
let _IDre15 =  /^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/
// 校验身份证:
if( _IDRe18.test( idVal ) || _IDre15.test( idVal )  ) {
	console.log(' 验证通过 ')
} else {
	console.log(' 验证未通过 ')
}

1. Structure number of
  citizen identity number is characteristic combination code, the 17th-digit code and a check code body composition. The order from left to right: six digit code address, date of birth eight-digit code, a three digit numerical sequence code and check code.
2. Address code
  represents the coding target permanent residence county (county-level cities, flag, district) administrative division code, according to the provisions GB / T2260's.
3. Date of Birth code
  represents the coding target birth year, month, day, according to the provisions GB / T7408, do not separators between the year, month, date code.
4. Order code
  representation within the region of the same address code identified, for the same year, the same month, people born the same day of the scheduled sequence number, odd-order code assigned to men, women assigned to the even number.
5. Checksum
  of the preceding seventeen digital code, according to ISO 7064: checksum calculation 1983.MOD 11-2 out check code.

Address code
1. North China: Beijing | 110000, Tianjin | 120000, Hebei | 130000, Shanxi | 140000, Inner Mongolia Autonomous Region | 150000
2. Northeast Region: Liaoning Province | 210000, Jilin Province | 220000, Heilongjiang Province | 230000
East: Shanghai | 310000, Jiangsu | 320000, Zhejiang | 330000, Anhui | 340000, Fujian | 350000, Jiangxi | 360000, Shandong Province | 370000, Taiwan (886) | 710000
3. Central China: Henan | 410000, Hubei | 420000, Hunan | 430000
4. South China: Guangdong Province | 440000, Guangxi Zhuang Autonomous Region | 450000, Hainan | 460000, Hong Kong SAR (852) | 810000, Macao Special Administrative Region (853) | 820,000
5. Southwest China: Sichuan Province | 510000, Guizhou | 520000, Yunnan | 530000, Tibet Autonomous Region | 540000, Chongqing | 500000
6. Northwest: Shaanxi | 610000, Gansu Province | 620000, Qinghai | 630000, Ningxia Hui Autonomous Region | 640000, Xinjiang Uygur Autonomous Region | 650000

Digital encoding rules address code of mainland China resident identity card numbers are as follows:
first, two represent the province (autonomous regions, municipalities and special administrative regions).
Third, four bits represent the (yard summary prefecture-level cities, autonomous prefectures and regions, and municipalities in their district and Union County) city. Among them, 01-20,51-70 represents the prefecture-level cities; 21-50 represents areas (prefectures and leagues).
Fifth, six represent the county (district, county-level cities, flag). 01-18 represents the prefecture-level cities, autonomous prefectures, regional, county-level city under the jurisdiction of the AU; 21-80 represents a county (banner); 81-99 represents the province directly under the county-level administrative units.

Birth date code
1. (ID number seventh to fourteenth) an encoding target birth year, month, day, year in which is represented by four digits without separators between year, month, day. For example: May 11, 1981, says with 19,810,511.

Order code
1. (ID number fifteenth to seventeen) within the region identified by the address code of the same year, month, people born scheduled sequence number. Which seventeenth odd given to men, women give an even number.

Check code
1. As the tail number of the checksum is calculated in accordance with the unified formula Prepared by the number, if someone's tail number is 0-9, X will not occur, but if the tail number is 10, so you have to use X instead, because if done with tail number 10, then the person's identity becomes 19, and 19 numbers in violation of national standards, and China's computer application system does not recognize the 19 ID number. Ⅹ is the Roman numeral 10, to replace the X-10, it can guarantee citizens' identity cards in line with national standards.

Published 58 original articles · won praise 20 · views 110 000 +

Guess you like

Origin blog.csdn.net/fly_wugui/article/details/88902156
Recommended