iOS determines if the bank card number is valid

Source: Internet
Author: User

iOS determines if the bank card number is valid by Wusheying
+ (BOOL) Isvalidcreditnumber: (nsstring*) value {BOOL result = NO;    Nsinteger length = [value length];        if (length >=) {result = [Wtcreditcard isvalidnumber:value]; if (result) {Nsinteger twodigitbeginvalue = [[Value substringwithrange:nsmakerange (0, 2)] IntegerValue]            ; VISA if ([Wtcreditcard isstartwith:value str:@ "4"]) {if (= = length| |                = = length) {result = TRUE;                }else {result = NO; }}//mastercard else if (twodigitbeginvalue >= Wuyi && twodigitbeginvalue <=            (&& length = =) {result = TRUE; }//american Express else if (([Wtcreditcard isstartwith:value str:@ "34"]| | [Wtcreditcard isstartwith:value str:@ "37"])            && length = = () {result = TRUE; }//discover else if ([WTCREDITCARd Isstartwith:value str:@ "6011"] && length = = +) {result = TRUE;            }else {result = FALSE;            }} if (result) {Nsinteger digitvalue;            Nsinteger checkSum = 0;            Nsinteger index = 0;            Nsinteger Leftindex;                Even length, odd index if (0 = = length%2) {index = 0;            Leftindex = 1;                }//odd length, even index else {index = 1;            Leftindex = 0; } while (Index < length) {digitvalue = [[Value Substringwithrange:nsmakerange (index, 1)] int                Egervalue];                Digitvalue = digitvalue*2;                if (Digitvalue >=) {checkSum + = DIGITVALUE/10 + digitvalue%10;                } else {checkSum + = Digitvalue;           }     Digitvalue = [[Value Substringwithrange:nsmakerange (Leftindex, 1)] integervalue];                CheckSum + = Digitvalue;                Index + = 2;            Leftindex + = 2; } result = (0 = = checksum%10)?        True:false;    }}else {result = NO; } return result;


iOS determines if the bank card number is valid

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.