我必须将输入字符串格式化为电话号码。因为我正在使用
(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger newLength = [textField.text length] + [string length] - range.length;
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS_ONLY] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
if (string.length==3||string.length==7) {
filtered =[filtered stringByAppendingString:@"-"];
}
return (([string isEqualToString:filtered])&&(newLength <= CHARACTER_LIMIT));
}
这里
#define NUMBERS_ONLY @"1234567890-"
#define CHARACTER_LIMIT 12
但它没有编辑回来。
请给出一些想法