Determine if the bank account is entered correctly

Source: Internet
Author: User

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

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.