


Two verification methods implemented by javascript or asp to determine whether the ID number is correct_javascript skills
The specific code is as follows:
1. Use javascript to verify:
<script> <BR>function checkIdcard(idcard){ <BR>var Errors=new Array( <BR>"Verification passed!", <BR>"Incorrect number of digits in ID number!", <BR>"The date of birth of the ID card number is out of the range or contains illegal characters!", <BR>"The ID card number is verified incorrectly!", <BR>"The ID card area is illegal!" <BR>); <BR>var area= {11:"Beijing",12:"Tianjin",13:"Hebei",14:"Shanxi",15:"Inner Mongolia",21:"Liaoning",22:"Jilin",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:"foreign"} <br><br>var idcard,Y,JYM; <BR>var S,M; <BR>var idcard_array = new Array(); <BR>idcard_array = idcard. split(""); <BR>//Area inspection<BR>if(area[parseInt(idcard.substr(0,2))]==null) return Errors[4]; <BR>//Identity number digit Number and format check <BR>switch(idcard.length){ <BR>case 15: <BR>if ( (parseInt(idcard.substr(6,2)) 1900) % 4 == 0 || ((parseInt( idcard.substr(6,2)) 1900) % 100 == 0 && (parseInt(idcard.substr(6,2)) 1900) % 4 == 0 )){ <BR>ereg=/^[1-9 ][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9 ]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]| [1-2][0-9]))[0-9]{3}$/;//Test the legality of birth date<BR>} else { <BR>ereg=/^[1-9][ 0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]| 3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[ 0-9]|2[0-8]))[0-9]{3}$/;//Test the legality of birth date<BR>} <BR>if(ereg.test(idcard)) return Errors [0]; <BR>else return Errors[2]; <BR>break; <BR>case 18: <BR>//18-digit identity number detection<BR>//Date of birth legality check<BR>/ /Leap year, month and day: ((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04 |06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9])) <BR>//Normal year, month and day: ((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1] )|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2 [0-8])) <BR>if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt( idcard.substr(6,4))%4 == 0 )){ <BR>ereg=/^[1-9][0-9]{5}19[0-9]{2}((01| 03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0 [1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[ 0-9Xx]$/;//Legacy regular expression for birth date in leap year<BR>} else { <BR>ereg=/^[1-9][0-9]{5}19[0-9] {2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06 |09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]) )[0-9]{3}[0-9Xx]$/;//The legal regular expression of birth date in ordinary years<BR>} <BR>if(ereg.test(idcard)){//Test birth date Legality<BR>//Calculate check digit<BR>S = (parseInt(idcard_array[0]) parseInt(idcard_array[10])) * 7 <BR> (parseInt(idcard_array[1]) parseInt(idcard_array[ 11])) * 9 <BR> (parseInt(idcard_array[2]) parseInt(idcard_array[12])) * 10 <BR> (parseInt(idcard_array[3]) parseInt(idcard_array[13])) * 5 <BR> (parseInt(idcard_array[4]) parseInt(idcard_array[14])) * 8 <BR> (parseInt(idcard_array[5]) parseInt(idcard_array[15])) * 4 <BR> (parseInt(idcard_array[6] ) parseInt(idcard_array[16])) * 2 <BR> parseInt(idcard_array[7]) * 1 <BR> parseInt(idcard_array[8]) * 6 <BR> parseInt(idcard_array[9]) * 3 ; <BR>Y = S % 11; <BR>M = "F"; <BR>JYM = "10X98765432"; <BR>M = JYM.substr(Y,1);//Judge the check digit<BR>if( M == idcard_array[17]) return Errors[0]; //Detect check digit of ID<BR>else return Errors[3]; <BR>} <BR>else return Errors[2]; <BR>break ; <BR>default: <BR>return Errors[1]; <BR>break; <BR>} <br><br>} <BR>alert(checkIdcard("220183198808081610")) <BR></script>> ;
2. Verify by asp code:
Function checkIDCard(idcard) '-1 is the correct ID card, otherwise it is an illegal ID card
Dim Y, JYM
Dim S, M
Dim area
area = "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"
Dim ereg
Set ereg = New regexp
'Area check
If InStr(1, area, Mid(idcard, 1, 2)) = 0 Then checkIDCard = 1: Exit Function
'ID number digits and format check
Select Case Len(idcard)
Case 15
If ((CInt(Mid(idcard, 7, 2)) 1900) Mod 4 = 0 or ((CInt(Mid(idcard, 7, 2)) 1900) Mod 100 = 0 And (CInt(Mid(idcard, 7, 2)) 1900) Mod 4 = 0)) Then
ereg.Pattern = "^[1-9][0-9]{5}[0- 9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04 |06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9])) [0-9]{3}$" ';//Test the legality of birth date
Else
ereg.Pattern = "^[1-9][0-9]{5}[0-9 ]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04| 06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8] ))[0-9]{3}$" ';//Test the legality of birth date
End If
If (ereg.test(idcard)) Then
checkIDCard = -1
Else
checkIDCard = 2
End If
Case 18
'//18-digit identity number detection
'//Date of birth legality check
If ((CInt(Mid( idcard, 7, 2)) 1900) Mod 4 = 0 or ((CInt(Mid(idcard, 7, 2)) 1900) Mod 100 = 0 And (CInt(Mid(idcard, 7, 2)) 1900) Mod 4 = 0)) Then
ereg.Pattern = "^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10| 12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2 ][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$" ';// Legal regular expression for birth date in leap year
Else
ereg.Pattern = "^[1-9][0-9]{5}19[0-9]{2}((01|03| 05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1 -9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3} [0-9Xx]$" ';//The legal regular expression of birth date in ordinary years
End If
If (ereg.test(idcard)) Then
'//Calculate check digit
S = (CInt(Mid(idcard, 0 1, 1)) CInt(Mid(idcard, 10 1, 1))) * 7 _
(CInt(Mid(idcard, 1 1, 1)) CInt( Mid(idcard, 11 1, 1))) * 9 _
(CInt(Mid(idcard, 2 1, 1)) CInt(Mid(idcard, 12 1, 1))) * 10 _
( CInt(Mid(idcard, 3 1, 1)) CInt(Mid(idcard, 13 1, 1))) * 5 _
(CInt(Mid(idcard, 4 1, 1)) CInt(Mid(idcard, 14 1, 1))) * 8 _
(CInt(Mid(idcard, 5 1, 1)) CInt(Mid(idcard, 15 1, 1))) * 4 _
(CInt(Mid( idcard, 6 1, 1)) CInt(Mid(idcard, 16 1, 1))) * 2 _
CInt(Mid(idcard, 7 1, 1)) * 1 _
CInt(Mid(idcard , 8 1, 1)) * 6 _
CInt(Mid(idcard, 9 1, 1)) * 3
Y = S Mod 11
M = "F"
JYM = "10X98765432 "
M = Mid(JYM, Y 1, 1)
If (M = Mid(idcard, 17 1, 1)) Then checkIDCard = -1 Else checkIDCard = 3
Else
checkIDCard = 4
End If
Case Else
checkIDCard = Len(idcard)
End Select
End Function%>

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools