Turn the 15-bit ID card into a 18-bit JS code

Source: Internet
Author: User
Original address: http://www.java2000.net/p11027
A piece of code provided by a user.
<title> convert 15-bit ID card into 18</title> <script language= "JavaScript" >     var  v = new array ();     var vs =  "10x98765432";     var newCardID =  "";     function onload ()     {         document.getelementbyid ("Cardid"). focus (); &NBSP;&NBSP;&NBSP;&NBSP}     function checkcardid (cardID15)     {          v.push (2, 4, 8, 5, 10, 9,  7,&NBSP;3,&NBSP;6,&NBSP;1,&NBSP;2,&NBSP;4,&NBSP;8,&NBSP;5,&NBSP;10,&NBSP;9,&NBSP;7);          var cardID = cardID15.value;          if (cardid.length!=15)          {            alert ("Please enter your ID number for 15 digits.") ");             cardid15.focus ();             return;         }         var  Month = cardid.substring (8,10)//Get a 15-digit number in the Month         if (! Checkmonth (month))          {               alert ("You entered the ID card format is incorrect, month fill error." ")               cardid15.focus ();               return;          }        var year  =  " + cardid.substring" (6,8);  &nBsp;     var day = cardid.substring (10,12);        if (!checkday (year,month,day))         {        alert ("you entered an incorrect format of the ID card, the date grid filled in error");          cardid15.focus ();         return; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP}      //alert (CheckDay (year,month,day));     //15-bit number converted to 17-bit     var cardIDcardID17 =  Cardid.substring (0,6) + "+cardid.substring" (6);     var N = 0;     var R = -1;     var T =  ' 0 '//save last digit     var j = 0;     var cardid18= "";     //count out 18th digit     for  (var i = 16; i >= 0; i--)     {             n += parseint (cardid17.substring (i, i + 1))  * v[j];             j++;     }     R = N % 11;     t = vs.charat (R);     cardID18 = cardID17 + T;     document.getelementbyid ("cardID18"). Value=cardid18;     newCardID = cardID18; //Determine if the month entered is correct function checkmonth (month) {    if (month<1| | MONTH&GT;12)     {        return false;      }     return true; /** * * Check that the number of days you enter is correct **yean for the year **month for the month **day for the day **/Function checkday (year,month,daY) {    var Mday = 0;     if (day<1| | day>31)     {        return false;   &NBSP;&NBSP;&NBSP}     if (month==1| | month==3| | month==5| | month==7| | month==8| |month==10| | MONTH==12)     {         Mday = 31; &NBSP;&NBSP;&NBSP;&NBSP}     if (month==4| | month==6| | month==9| | month==11)     {         Mday = 30; &NBSP;&NBSP;&NBSP;&NBSP}     if (month==2)     {          mday = isleapyear (year); &NBSP;&NBSP;&NBSP;&NBSP}     if (day>mday)     {         return false;     }     return true; //Determine if the year you entered is a leap years function isleapyear {    return  (year % 4 ==  0 && year % 100 != 0)  | |   (year % 400 == 0)  ? 29 : 28; Function checknewcardid () {alert ("18-bit ID number is:" +newcardid);} </script> <body onload= "onload ()" > 15-digit number: <input id= "Cardid" type= "text" maxlength= "onmouseout=" Checkcardid "(This)" /></br> 18-digit number: <input id= "cardID18" type= "text" readonly= "readonly"/>
<input type= "button" onclick= "Checknewcardid ();" value= "Submit"/> </body>

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.