I have searched the site for my answer, however I think it is also how I got myself into this problem.
I'm trying to limit my 1 and only text field to 10 characters and only numbers.
Below is code mostly off other questions on this site. What I am trying to do is mash this code together for my limits
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:LEGAL] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
NSString *newString = [myTextField.text stringByReplacingCharactersInRange:range withString:filtered];
return !([newString length] > 10);
}
There are no problems with my build until I click my textfield... but I get a green arrow warning stating " thread stopped at breakpoint 1 " I've tried a few different things now, but now feel I am stumped, I'm hoping this is something real easy for someone here...
they will work individually (one or the other) with the code below, but I can't seem to get them working together.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *newString = [myTextField.text stringByReplacingCharactersInRange:range withString:string];
return !([newString length] > 10);
}
This will limit my input to 10 and ...
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:LEGAL] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}
This also restricts my input to numbers only with no problems. provided I defined LEGAL as only numbers...
I just can't seem to get them to work together... Can anyone help me with this one ???