JavaScript ID Valid validation details and example code

Source: Internet
Author: User
Tags gettext

JavaScript ID Valid validation details and example code this article mainly introduces the JavaScript ID card valid verification detailed and the case code of the relevant information, the need for friends can refer to the following

JavaScript Authentication ID Number

12345678910111213141516171819202122232425262728293031323334353637383940414243444546 <%@ page language="java" contentType="text/html; charset=GB18030"  pageEncoding="GB18030"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><meta http-equiv="Content-Type" content="text/html; charset=GB18030"><title>身份证验证</title><script type="text/javascript"> var arr2=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];var arr3=[1,0,‘X‘,9,8,7,6,5,4,3,2];function checkid(){  var t=document.getElementById("gettext").value;  if(t.length==18){    var arr=t.split(‘‘);    var s;    var reg = /^\d+$/;    var pd=0;    for(i=0;i<17;i++){      if(reg.test(arr[i])){        s=true;        pd=arr[i]*arr2[i]+pd;      }else{        s=false;        break;      }    }    if(s=true){      var r=pd%11;      if(arr[17]==arr3[r]){        document.getElementById("show").innerHTML="身份证号合法  尾号为:"+arr3[r];      }else{        document.getElementById("show").innerHTML="非合法身份证号";      }    }      }else{    document.getElementById("show").innerHTML="非合法身份证号";  }}</script><body ><input id="gettext" type="text" size="30" onkeyup="checkid()"><p id="show"></p><br></body>

Based on the Online ID card calculation formula written by a verification ID number JS

Step One: multiply the 1th digit of the ID number with 7, multiply the 2nd digit of the ID number with 9, multiply the 3rd digit of the ID number with 10, multiply the 4th digit of the ID number with 5, and multiply the 5th digit of the ID number by 8 , multiply the 6th digit of the ID number with 4, multiply the 7th digit of the ID number with 2, multiply the 8th digit of the identity card number with 1, multiply the 9th digit of the identity card number with 6; Multiply the 10th digits of the ID number with 3, and multiply the 11th digits of the ID number by 7 , multiply the 12th digit of the identity card number with 9, multiply the 13th digit of the ID number with 10, multiply the 14th digit of the identity card number with 5, multiply the 15th digit of the ID number with 8, multiply the 16th digit of the ID number with 4, and multiply the 17th digit of the ID number with 2.

The second step: The first step ID number 1~17 phase multiply the result sum, all add up.

The third step: The result calculated by the second step is divided by 11, so that the remainder is 0, the remainder is 1, the remainder is 2, the remainder is 3, the remainder is 4, the remainder is 5, the remainder is 6, the remainder is 7, the remainder is 8, the remainder is 9, the remainder is 10 altogether 11 kinds of possibility.

Fourth Step: If the remainder is 0, the corresponding last ID number is 1, if the remainder is 1, the corresponding last ID number is 0; if the remainder is 2, the number of the corresponding last ID is x; if the remainder is 3, the number of the last identity card corresponding to 9 If the remainder is 4, the number of the corresponding last identity card is 8, and if the remainder is 5, the number of the corresponding last identity card is 7; If the remainder is 6, the number of the corresponding last ID is 6; If the remainder is 7, the number of the last identity card corresponds to 5; If the remainder is 8, The number of the corresponding last identity card is 4, if the remainder is 9, the number of the corresponding last ID is 3, and if the remainder is 10, then the number of the last identity card corresponds to 2.

(reproduced) http://www.jb51.net/article/95287.htm

JavaScript ID Valid validation details and example code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.