Created
June 15, 2012 00:31
-
-
Save asparagui/2933861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { | |
//NSLog(@"textfield hit: %@", textField.placeholder); | |
if (string.length == 0) { | |
return YES; | |
} | |
if (textField == self.CardholderName) { | |
return YES; | |
} else { | |
NSUInteger newLength = [textField.text length] + [string length] - range.length; | |
if (textField == self.CardNumber) { | |
if (newLength > 16) { | |
return NO; | |
} | |
} | |
if (textField == self.ExpiryDate) { | |
if (newLength > 4) { | |
return NO; | |
} | |
} | |
if (textField == self.CCV) { | |
if (newLength > 4) { | |
return NO; | |
} | |
} | |
if (textField == self.ZipCode) { | |
if (newLength > 5) { | |
return NO; | |
} | |
} | |
NSCharacterSet *nonNumberSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; | |
return [string rangeOfCharacterFromSet:nonNumberSet].location == NSNotFound; | |
} | |
return NO; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment