I am using a UITextField
and needing to enforce the following date format:
12/17
I know how to enforce the 4 character limit:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ([textField isEqual:self.billingExpirationDate]) {
if (range.length + range.location > textField.text.length) {
return NO;
}
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return newLength <= 4;
}
return YES;
}
However, if I try to insert the / into the string after two numbers have been typed, it screws things up and won't let the user use the delete button.
Does anyone have any ideas how I could follow the needed format, while only allowing users to enter four numeric characters, and obviously letting them delete them if needed?
You can use this for Delete characters.
Let me know if you need for more Help. Thanks.....