Verify the bank card number

Source: Internet
Author: User

Transfer from Http://blog.csdn.net/zheng963/article/details/49299993  //Description:   Bank card number Luhm check     //luhm Check rule: 16-digit bank card number (19-bit universal):       //1.15 (or 18) bit card numbers without check digit are numbered 1 through 15 (18) from right, multiplied by the number on the odd digit number 2.    //2. Add all 10 bits of the singular product, plus the numbers on all even digits.    //3. The addition and calibration potentials are divisible by 10.     function Luhmcheck (bankno) {if (Bankno.length < + | Bankno.length >) {//$ ("#banknoInfo"). HTML ("bank The card number must be between 16 and 19 "); return false;} var num =/^\d*$/;  //full digit if (!num.exec (Bankno)) {//$ ("#banknoInfo"). HTML ("bank card number must be all numbers"); return false;} Start with 6-bit var strbin= " 10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99 ";    if (Strbin.indexof (bankno.substring (0, 2) = =-1) {//$ ("#banknoInfo"). HTML ("bank card number begins 6 bits not conforming to specification"); return false ;}         var lastnum=bankno.substr (bankno.length-1,1);//Remove Last (compare with Luhm)              var first15num=bankno.substr (0,bankno.lengtH-1)///First 15 or 18 bits         var newarr=new Array ();        for (Var i=first15num.length- 1;i>-1;i--) {   //pre-15 or 18-bit reverse deposit into array             Newarr.push (First15num.substr (i, 1);       }        var arrjishu=new Array ();  //odd digit <9        var arrjishu2=new Array (); Odd digits of the product >9                var arroushu=new Array ();  //even bit array         for (var j=0;j<newarr.length;j++) {            IF ((j+1)%2==1) {//odd digit                 if (parseint (Newarr[j]) *2<9)         &N Bsp       Arrjishu.push (parseint (newarr[j));                ELSE&NB Sp               Arrjishu2.push (parseint (newarr[j));      &NBSp    }            else//even digit             Arroushu.push (Newarr[j]);       }                var jishu_child1=new Array ();//Odd digit * * >9 the number of bits after the partition         var jishu_child2=new array ();//ODD digits * * * >9 after the partition of the array 10 digits &nbsp ;       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; Array of odd digits * < 9         var sumoushu=0; Sum of the even-bit arrays         var sumjishuchild1=0; Odd Digit * * >9 after the partition of the array of single-digit sum         var sumjishuchild2=0; Odd Digit * * >9 after the split array 10-digit sum         var sumtotal=0;        for (var m=0;m<arrjishu.length;m++) {            SUMJ Ishu=sumjishu+parseint (Arrjishu[m]);       }              and nbsp 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) +par Seint (Sumoushu) +parseint (sumJiShuChild1) +parseint (sumJiShuChild2);               /Calculate LUHM values       &NBSP; var k= parseint (sumtotal)%10==0?10:parseint (sumtotal)%10;                var luhm= 10-k;            &NBSP ;   if (LASTNUM==LUHM) {        $ ("#banknoInfo"). HTML ("Luhm Verification Pass");        Return true;       }        else{        $ ("#banknoInfo"). htm L ("bank card number must conform to LUHM check");        return false;       }       &NBSP;&NBS P  }

Verify the bank card number (GO)

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.