In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you based on the Luhn algorithm format to verify whether the bank card number entered by the user is correct, I hope you will gain something after reading this article, let's discuss it together!
IOS Code:
/ * * @ param cardNo bank card number * * @ return * / + (BOOL) checkCardNo: (NSString*) cardNo {int oddsum = 0; / / odd summation int evensum = 0; / / even summation 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)) {NSString * tmpString = [cardNo substringWithRange:NSMakeRange (imuri 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;}
Androd Code:
/ * matching Luhn algorithm: it can be used to detect the bank card number * @ param cardNo * @ return * / public static boolean matchLuhn (String cardNo) {int [] cardNoArr = new int [cardNo.length ()]; for (int isidentin I = 0transferiMusure 2) {cardNoArr [I]
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.