Bank card algorithm Rules

Source: Internet
Author: User

/** *luhn Calibration Algorithm verifies bank card number *description: Bank card number luhm check *luhm check rule: 16-digit bank card number (19-bit generic): * *. 15 (or 18) bit cards with no check digit numbered 1 to 15 (18) from right    , the number on the odd digit number is multiplied by 2.    * *. Add all 10 bits of the singularity product, plus the numbers on all even digits.    The addition and calibration potentials are divisible by 10. * Method steps are clear, easy to understand, need to refer to the page Jquery.js *bankno for the bank card number */function Luhmcheck (bankno) {var lastnum = bankno.substr (ba Nkno.length-1, 1);//Take Out the last one (compared to luhm) var first15num = bankno.substr (0, bankno.length-1);//First 15 or 18-bit var n        Ewarr = new Array ();        for (var i = first15num.length-1; i >-1; i--) {///First 15 or 18-bit reverse-deposit into array newarr.push (FIRST15NUM.SUBSTR (i, 1));  } var Arrjishu = new Array (); The product <9 var arrJiShu2 = new Array () of odd digits * *;  The product >9 var Arroushu = new Array () of odd digits * *; An even-bit array for (var j = 0; J < Newarr.length; J + +) {if ((j + 1)% 2 = = 1) {//odd digit if (par                Seint (Newarr[j]) * 2 < 9) Arrjishu.push (parseint (Newarr[j]) * 2); else ARRJISHU2.PUsh (parseint (Newarr[j]) * 2);        } else//even digit Arroushu.push (newarr[j]); } var jishu_child1 = new Array ();//Odd digit * * >9 after the partition of the array single-digit var jishu_child2 = new Array ();//Odd Digit * * &GT;9 Division            After the array of 10-digit for (var h = 0; h < arrjishu2.length; h++) {Jishu_child1.push (parseint (arrjishu2[h])% 10);        Jishu_child2.push (parseint (arrjishu2[h])/10); } var Sumjishu = 0; The sum of the array of odd digits * < 9 is var Sumoushu = 0; The sum var of an even-bit array is sumJiShuChild1 = 0; Odd Digit * * >9 after the partition of the array of single-digit and var sumJiShuChild2 = 0;        Odd Digit * * >9 after the partition of the array of 10-digit and var sumtotal = 0;        for (var m = 0; m < arrjishu.length; m++) {Sumjishu = Sumjishu + parseint (arrjishu[m]);        } for (var n = 0; n < arroushu.length; n++) {Sumoushu = Sumoushu + parseint (Arroushu[n]); } for (var p = 0; p < jishu_child1.length; p++) {sumJiShuChild1 = SumJiShuChild1 + parseint (jISHU_CHILD1[P]);        SumJiShuChild2 = sumJiShuChild2 + parseint (jishu_child2[p]); }//Calculate sum SumTotal = parseint (Sumjishu) + parseint (Sumoushu) + parseint (sumJiShuChild1) + parseint (Sumjishuch        ILD2); Calculate Luhm value var k = parseint (sumtotal)% 10 = = 0?        10:parseint (sumtotal)% 10;        var luhm = 10-k;        var my = false;        if (Lastnum = = luhm) {//luhm verified through my = true;        } else {//bank card number must conform to LUHM check my = false;    } return my; }

  

Bank card algorithm Rules

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.