Determine whether the bank account is entered correctly and whether the bank account is entered

Source: Internet
Author: User

Determine whether the bank account is entered correctly and whether the bank account is entered

Not to mention that you can directly paste the code and enter the bank card number to make a judgment.
-(Void) viewDidLoad {[super viewDidLoad]; NSString * str = @ "6226820011200783033"; BOOL isRight = [self checkCardNo: str]; if (! IsRight) {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "not" message: @ "Please re-enter the card number" delegate: nil cancelButtonTitle: nil failed: nil, nil]; [alert show];} else {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "to" message: @ "" delegate: nil cancelButtonTitle: nil otherButtonTitles: nil, nil]; [alert show] ;}}


// This is the judgment method.

-(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 % 10) = 0) return YES; else return NO ;}


Related Article

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.