Также для формата + x (xxx) xxx-xx-xx вы можете использовать что-то вроде этого простого решения:
+ (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
NSArray *components = [newString componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
NSString *decimalString = [components componentsJoinedByString:@""];
if (decimalString.length > 11) {
return NO;
}
NSMutableString *formattedString = [NSMutableString stringWithString:decimalString];
[formattedString insertString:@"+" atIndex:0];
if (formattedString.length > 2)
[formattedString insertString:@" (" atIndex:2];
if (formattedString.length > 7)
[formattedString insertString:@") " atIndex:7];
if (formattedString.length > 12)
[formattedString insertString:@"-" atIndex:12];
if (formattedString.length > 15)
[formattedString insertString:@"-" atIndex:15];
textField.text = formattedString;
return NO;}