//定义一个特殊字符的集合
NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"@/:;()¥「」"、;[]{}#%-*+=_\\|~<>$€^•'@#$%^&*()_+'\""];
//过滤字符串的特殊字符
NSString *oldString = _filterTextField.text;
//stringByTrimmingCharactersInSet能做到的仅仅是把字符串两端的非法字符过滤,但是包含在字符串里非法字符则无能为力。
NSString *newString = [[oldString componentsSeparatedByCharactersInSet:characterSet]componentsJoinedByString:@""];
self.filterTextField.text = newString;
网友评论