In order to create a better user experience, while reducing the pressure on the server side, for some such as, mobile phone number, bank card number, ID number to determine whether the correct is very necessary
Here is a small paragraph to determine whether the bank card number input is correct code method for your reference
- -(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 nil];
- [Alert Show];
- }else{
- Uialertview *alert = [[Uialertview Alloc]initwithtitle:@ ' to ' message:@ ' delegate: Nil Cancelbuttontitle: Nil otherbuttontitles: nil, nil nil];
- [Alert show];}
- }
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;
- }
iOS determines whether the bank card number entered by the user is correct