Do not say the direct sticker code to enter the bank card number can be judged
-(void) viewdidload { [super viewdidload]; NSString *str = @ "6226820011200783033"; BOOL isright = [self checkcardno:str]; if (!isright) { Uialertview *alert = [[Uialertview alloc]initwithtitle:@ ' not ' message:@ ' please reenter card number ' Delegate:nil Cancelbuttontitle:nil Otherbuttontitles:nil, nil]; [Alert show]; } else{ Uialertview *alert = [[Uialertview alloc]initwithtitle:@ "to" message:@ "" Delegate:nil CancelButtonTitle:nil Otherbuttontitles:nil, nil]; [Alert show];}}
That's the way to judge.
-(BOOL) Checkcardno: (nsstring*) cardno{int oddsum = 0; Odd sum int evensum = 0; even sum int allsum = 0; int cardnolength = (int) [Cardno length]; int lastnum = [[Cardno substringfromindex:cardnolength-1] intvalue]; Cardno = [Cardno substringtoindex:cardnolength-1]; for (int i = cardNoLength-1; i>=1;i--) {NSString *tmpstring = [Cardno substringwithrange:nsmakerange (I-1, 1)] ; int tmpval = [tmpstring intvalue]; if (cardnolength% 2 ==1) {if ((i% 2) = = 0) {tmpval *= 2; if (tmpval>=10) tmpval-= 9; Evensum + = Tmpval; }else{oddsum + = Tmpval; }}else{if ((i% 2) = = 1) {Tmpval *= 2; if (tmpval>=10) tmpval-= 9; Evensum + = Tmpval; }else{oddsum + = Tmpval; }}} allsum = Oddsum + EvensuM Allsum + = Lastnum; if ((allsum%) = = 0) return YES; else return NO;}
Determine if the bank account is entered correctly