I need help with code that looks at a textfield make sure it starts with either a (+ or -) then has 3 integers after it.
So valid data looks like +234 or -888
So I have started this code but there are 2 problems with it
It correctly validates that only 4 characters are entered. But for some reason you have to take focus off the textfield in order for the Done button on the keyboard to fire and hide the keyboard. If I only put less than 4 characters in the textfield then the Done button works fine. But I dont want the user to enter anything but 4 characters and then press Done and hide the keyboard. Thats the first problem....
I am not familar with regular expressions and how to use them in iphone. So I need to add to this code regular expression for the above requirement.
-(BOOL)textField:(UITextField*)textFieldshouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; return !([newString length] > 4); } //Done button to hide the keyboard -(IBAction)Done:(id)sender { }