From cbca89358c8e5da5071d6d42ce15cb9be7ccc030 Mon Sep 17 00:00:00 2001 From: Fedya Skitsko Date: Thu, 3 Oct 2013 13:47:42 +0300 Subject: [PATCH] Restrict user to type month more than 12 --- .../Cells/RETableViewCreditCardCell.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/RETableViewManager/Cells/RETableViewCreditCardCell.m b/RETableViewManager/Cells/RETableViewCreditCardCell.m index 1582b60..6216c95 100644 --- a/RETableViewManager/Cells/RETableViewCreditCardCell.m +++ b/RETableViewManager/Cells/RETableViewCreditCardCell.m @@ -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