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