A question about the bank card number rules, according to the rules for bank card verification

Source: Internet
Author: User

Currently, the first six digits of the current 16-digit UnionPay card number are 622126 ~ Between 622925, 7 to 15 digits are customized by the bank,
It may be a card issuing branch, card issuing outlet, card issuing number, and 16th bits are verification codes.

The 16-bit card number verification bit is calculated using the luhm verification method:

1. Numbers 1 to 15 of the 15-digit card numbers without verification digits are numbered from right to 15, and the numbers on the odd-digit number are multiplied by 2.
2. Add all the ten digits of the odd-bits product and all the numbers on the even-bits.
3. The addition and addition of the check bit can be divided by 10.

For example, the card number:

6 2 2 5 8 8 1 4 4 2 0 7 4 3*2 2 2 2 2 2 2 2 ------------------------------------------------------ 12 2 4 5 16 8 2 4 2 4 4 14 4 6 will the preceding number addition: 1 + 2 + 2 + 4 + 5 + 1 + 6 + 8 + 2 + 4 + 2 + 4 + 4 + 1 + 4 + 4 + 6 = 60 due to 60 + 0 divided by 10, therefore, the checkpoint is 0, so the card number is 6225 8814 1420.

If one of the digits is replaced, the last check bit is incorrect.

I wrote a program for computation:

Public class test5 {public static void main (string [] ARGs) {string card = "622588141420743"; system. out. println ("card:" + card); system. out. println ("Check Code:" + getbankcardcheckcode (card); system. out. println ("card ID:" + card + getbankcardcheckcode (card ));} /*** verify the bank card number * @ Param cardid * @ return */public static Boolean checkbankcard (string cardid) {char bit = getbankcardcheckcode (Car Did. substring (0, cardid. length ()-1); Return cardid. charat (cardid. length ()-1) = bit ;} /*** obtain the checkpoint from the bank card number without the checkpoint using the luhm Verification Algorithm * @ Param noncheckcodecardid * @ return */public static char getbankcardcheckcode (string noncheckcodecardid) {If (noncheckcodecardid = NULL | noncheckcodecardid. trim (). length () = 0 |! Noncheckcodecardid. Matches ("// D +") {Throw new illegalargumentexception ("bank card code must be number! ");} Char [] CHS = noncheckcodecardid. trim (). tochararray (); int luhmsum = 0; For (INT I = chs. length-1, j = 0; I> = 0; I --, J ++) {int K = CHS [I]-'0 '; if (J % 2 = 0) {K * = 2; k = K/10 + K % 10;} luhmsum + = K ;} return (luhmsum % 10 = 0 )? '0': (char) (10-luhmsum % 10) + '0 ');}}

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.