JavaScript turns 15-bit IDs into 18 function _javascript tips

Source: Internet
Author: User
<ptml> <pead> <title>javascript 15-bit ID to 18</title> <script language= "JavaScript" > var v = new Array (); var vs = "10x98765432"; var newcardid = ""; function onload () {document.getElementById ("Cardid"). focus (); The function Checkcardid (cardID15) {V.push (2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4, 8, 5, 10, 9, 7); var cardid = Cardid15.value; if (cardid.length!=15) {alert ("Please enter your ID number 15)!" "); Cardid15.focus (); Return var month = cardid.substring (8,10);//Get the month of 15-digit number if (!checkmonth (month)) {alert ("you entered the ID card format is incorrect, month fill error!") ") Cardid15.focus (); Return var year = "n" + cardid.substring (6,8); var day = cardid.substring (10,12); if (!checkday (Year,month,day)) {alert ("you entered an incorrect format for the ID card, the date grid is filled in incorrectly"); Cardid15.focus (); Return }//alert (Checkday (year,month,day)); Converts the 15-bit number to 17-bit var cardID17 = 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 the 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&GT;31) {return false; } if (month==1| | month==3| | month==5| | month==7| | month==8| |month==10| | month==12) {mday = 31; } if (month==4| | month==6| | month==9| | month==11) {mday = 30; } if (month==2) {mday = Isleapyear (year); } if (Day>mday) {return false; return true; //Determine if the year you entered is a leap years function Isleapyear {return (annual% 4 = 0 && Year% 100!= 0) | | (Year% 400 = 0)? 29:28; function Checknewcardid () {alert ("18-bit ID number is:" +newcardid); } </script> </pead> <body onload= "onLoad () > 15-bit number: <input id= "Cardid" type= "text" maxlength= "onmouseout=" Checkcardid (This) "/></br> 18-bit number: <input id= "cardID18" type= "text" readonly= "readonly"/> <input type= "button" onclick= "Checknewcardid () ; "Value="/> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Related Article

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.