


js verifies whether the real name matches the ID number_javascript skills
In recent projects, an interface needs to be called for real-name authentication. The price of the real-name authentication interface is a few cents higher than that of SMS. Therefore, the conditions for calling real-name authentication must be strictly controlled, so js is used to verify the authenticity. Name and js verification ID number.
Get to the point
js verifies the real name and uses unicode characters for matching. The length of Chinese names is generally 2-4, so the match is repeated {2, 4} times
1.js verify real name
var regName =/^[\ue-\ufa]{,}$/; if(!regName.test(name)){ alert('真实姓名填写有误'); return false; }
js verification ID number, China’s ID number, the first-generation ID card number is 15 digits, the second-generation ID card number is 18 digits, the last check digit may be a number or 'X ' or 'x', so there are four possibilities: a. 15 digits b. 18 digits c. 17 digits, the eighteenth digit is 'X' d. 17 digits, the eighteenth digit is 'x' '
2.js verification of ID number
var regIdNo = /(^\d{}$)|(^\d{}$)|(^\d{}(\d|X|x)$)/; if(!regIdNo.test(idNo)){ alert('身份证号填写有误'); return false; }
PS:15位和18位身份证JS校验实例
一、身份证号码的结构和表示形式
1、号码的结构
根据〖中华人民共和国国家标准GB11643-1999〗中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。
2、地址码
表示编码对象常住户口所在县(市、旗、区)的行政区划代码,按GB/T2260的规定执行。
3、出生日期码
表示编码对象出生的年、月、日,按GB/T7408的规定执行,年、月、日代码之间不用分隔符。
4、顺序码
表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编定的顺序号,顺序码的奇数分配给男性,偶数分配给女性。
5、校验码
(1)十七位数字本体码加权求和公式
S = Sum(Ai * Wi), i = 0, ... , 16 , 先对前17位数字的权求和
Ai:表示第i位置上的身份证号码数字值
Wi:表示第i位置上的加权因子
7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
(2)计算模
Y = mod(S, 11)
(3)通过模得到对应的校验码
Y: 0 1 2 3 4 5 6 7 8 9 10
校验码: 1 0 X 9 8 7 6 5 4 3 2
也就是说,如果得到余数为1则最后的校验位p应该为对应的0。
15位的号码:
a a b b c c y y m m d d x x s
18位的号码:
a a b b c c y y y y m m d d x x s p
二、地址码
身份证前6位为行政区划数字代码(简称数字码)说明(参考《GB/T 2260-2007 中华人民共和国行政区划代码》):该数字码的编制原则和结构分析,它采用三层六位层次码结构,按层次分别表示我国各省(自治区,直辖市,特别行政区)、市(地区,自治州,盟)、县(自治县、县级市、旗、自治旗、市辖区、林区、特区)。
(1)第1、2位数字:所在省份编码,表示省、自治区、直辖市、特别行政区。
省,直辖市代码表: { 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:"国外"}
(2)第3、4位数字:所在省级市(县)编码,表示市、地区、自治州、盟、直辖市所辖市辖区、县汇总码、省(自治区)直辖县级行政区划汇总码。
——01~20、51~70表示市,直辖市则01表示市区,02以后表示直辖市辖区内的郊县;
——21~50表示地区、自治州、盟;
——90表示省(自治区)直辖县级行政区划汇总码。
(3)第5、6位数字:所在地级县(市)编码,表示县、自治县、县级市、旗、自治旗、市辖区、林区、特区。
——01~20表示市辖区、地区(自治州、盟)辖县级市、市辖特区以及省(自治区)直辖县级行政区划中的县级市,01通常表示辖区汇总码;
——21~80表示县、自治县、旗、自治旗、林区、地区辖特区;
——81~99表示省(自治区)辖县级市。
三、其它
15位身份证号码:
第7、8位为出生年份(两位数,用年份的后两位表示),
第9、10位为出生月份,
第11、12位代表出生日期,
第13、14位为顺序码,这个是随机数,
第15位代表性别,奇数为男,偶数为女。
18位身份证号码:
第7、8、9、10位为出生年份(四位数),
第11、12位为出生月份,
第13、14位代表出生日期,
第15、16位为顺序码,
第17位代表性别,奇数为男,偶数为女。
最后一位为校验位。
四、Js代码实例
var idCardNoUtil = { /*省,直辖市代码表*/ provinceAndCitys: {:"北京",:"天津",:"河北",:"山西",:"内蒙古",:"辽宁",:"吉林",:"黑龙江", :"上海",:"江苏",:"浙江",:"安徽",:"福建",:"江西",:"山东",:"河南",:"湖北",:"湖南",:"广东", :"广西",:"海南",:"重庆",:"四川",:"贵州",:"云南",:"西藏",:"陕西",:"甘肃",:"青海",:"宁夏", :"新疆",:"台湾",:"香港",:"澳门",:"国外"}, /*每位加权因子*/ powers: ["","","","","","","","","","","","","","","","",""], /*第位校检码*/ parityBit: ["","","X","","","","","","","",""], /*性别*/ genders: {male:"男",female:"女"}, /*校验地址码*/ checkAddressCode: function(addressCode){ var check = /^[-]\d{}$/.test(addressCode); if(!check) return false; if(idCardNoUtil.provinceAndCitys[parseInt(addressCode.substring(,))]){ return true; }else{ return false; } }, /*校验日期码*/ checkBirthDayCode: function(birDayCode){ var check = /^[-]\d{}(([-])|([-]))(([-])|([-][-])|([-]))$/.test(birDayCode); if(!check) return false; var yyyy = parseInt(birDayCode.substring(,),); var mm = parseInt(birDayCode.substring(,),); var dd = parseInt(birDayCode.substring(),); var xdata = new Date(yyyy,mm-,dd); if(xdata > new Date()){ return false;//生日不能大于当前日期 }else if ( ( xdata.getFullYear() == yyyy ) && ( xdata.getMonth () == mm - ) && ( xdata.getDate() == dd ) ){ return true; }else{ return false; } }, /*计算校检码*/ getParityBit: function(idCardNo){ var id = idCardNo.substring(,); /*加权 */ var power = ; for(var i=;i<;i++){ power += parseInt(id.charAt(i),) * parseInt(idCardNoUtil.powers[i]); } /*取模*/ var mod = power % ; return idCardNoUtil.parityBit[mod]; }, /*验证校检码*/ checkParityBit: function(idCardNo){ var parityBit = idCardNo.charAt().toUpperCase(); if(idCardNoUtil.getParityBit(idCardNo) == parityBit){ return true; }else{ return false; } }, /*校验位或位的身份证号码*/ checkIdCardNo: function(idCardNo){ //位和位身份证号码的基本校验 var check = /^\d{}|(\d{}(\d|x|X))$/.test(idCardNo); if(!check) return false; //判断长度为位或位 if(idCardNo.length==){ return idCardNoUtil.checkIdCardNo(idCardNo); }else if(idCardNo.length==){ return idCardNoUtil.checkIdCardNo(idCardNo); }else{ return false; } }, //校验位的身份证号码 checkIdCardNo: function(idCardNo){ //位身份证号码的基本校验 var check = /^[-]\d{}(([-])|([-]))(([-])|([-][-])|([-]))\d{}$/.test(idCardNo); if(!check) return false; //校验地址码 var addressCode = idCardNo.substring(,); check = idCardNoUtil.checkAddressCode(addressCode); if(!check) return false; var birDayCode = '' + idCardNo.substring(,); //校验日期码 return idCardNoUtil.checkBirthDayCode(birDayCode); }, //校验位的身份证号码 checkIdCardNo: function(idCardNo){ //位身份证号码的基本格式校验 var check = /^[-]\d{}[-]\d{}(([-])|([-]))(([-])|([-][-])|([-]))\d{}(\d|x|X)$/.test(idCardNo); if(!check) return false; //校验地址码 var addressCode = idCardNo.substring(,); check = idCardNoUtil.checkAddressCode(addressCode); if(!check) return false; //校验日期码 var birDayCode = idCardNo.substring(,); check = idCardNoUtil.checkBirthDayCode(birDayCode); if(!check) return false; //验证校检码 return idCardNoUtil.checkParityBit(idCardNo); }, formateDateCN: function(day){ var yyyy =day.substring(,); var mm = day.substring(,); var dd = day.substring(); return yyyy + '-' + mm +'-' + dd; }, //获取信息 getIdCardInfo: function(idCardNo){ var idCardInfo = { gender:"", //性别 birthday:"" // 出生日期(yyyy-mm-dd) }; if(idCardNo.length==){ var aday = '' + idCardNo.substring(,); idCardInfo.birthday=idCardNoUtil.formateDateCN(aday); if(parseInt(idCardNo.charAt())%==){ idCardInfo.gender=idCardNoUtil.genders.female; }else{ idCardInfo.gender=idCardNoUtil.genders.male; } }else if(idCardNo.length==){ var aday = idCardNo.substring(,); idCardInfo.birthday=idCardNoUtil.formateDateCN(aday); if(parseInt(idCardNo.charAt())%==){ idCardInfo.gender=idCardNoUtil.genders.female; }else{ idCardInfo.gender=idCardNoUtil.genders.male; } } return idCardInfo; }, /*位转位*/ getId: function(idCardNo){ if(idCardNo.length==){ return idCardNo; }else if(idCardNo.length==){ return idCardNo.substring(,) + idCardNo.substring(,); }else{ return null; } }, /*位转位*/ getId: function(idCardNo){ if(idCardNo.length==){ var id = idCardNo.substring(,) + '' + idCardNo.substring(); var parityBit = idCardNoUtil.getParityBit(id); return id + parityBit; }else if(idCardNo.length==){ return idCardNo; }else{ return null; } } }; //身份证号码验证 jQuery.validator.addMethod("idCardNo", function(value, element) { return this.optional(element) || idCardNoUtil.checkIdCardNo(value); }, "Please specify a valid ID number."); //获取身份证信息 var idCardInfo = idCardNoUtil.getIdCardInfo(idCardNo); alert(idCardInfo.gender + "|" + idCardInfo.birthday);
Note: When entering and judging whether the same ID card already exists in the database
(1) If you enter a 15-digit ID card: first check whether the 15-digit ID exists. If it does not exist, you need to convert the 15-digit ID card into an 18-digit ID card. If it still does not exist, you can Enter the system.
(2) If you enter an 18-digit ID card: first check whether the 18-digit ID exists. If it does not exist, you need to convert the 18-digit ID card into a 15-digit ID card. If it still does not exist, you can Enter the system.
If you find the corresponding 15-digit ID card, you need to update the 15-digit ID to 18-digit.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

How to use JS and Baidu Maps to implement map polygon drawing function. In modern web development, map applications have become one of the common functions. Drawing polygons on the map can help us mark specific areas for users to view and analyze. This article will introduce how to use JS and Baidu Map API to implement map polygon drawing function, and provide specific code examples. First, we need to introduce Baidu Map API. You can use the following code to import the JavaScript of Baidu Map API in an HTML file
