Restrict user to type month more than 12

This commit is contained in:
Fedya Skitsko
2013-10-03 13:47:42 +03:00
parent e3f86635b0
commit cbca89358c

View File

@@ -302,4 +302,17 @@ static inline NSString * RECreditCardType(NSString *creditCardNumber)
return YES;
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField == self.expirationDateField) {
if (range.location == 1) {
NSInteger month = [NSString stringWithFormat:@"%@%@", self.expirationDateField.text, string].integerValue;
if (month > 12) {
return NO;
}
}
}
return YES;
}
@end