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 ;}