1.
- (BOOL)checkSpecialCharacter:(NSString *)string { NSString *regex = @"[`~!@#$^&*()=|{}‘:;‘,\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“‘。,、?]+"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; return [pred evaluateWithObject:string]; }
https://www.jianshu.com/p/88be28860cde
__block BOOL isMatch = NO; NSString *letters = @"( ???????? )?(?﹏?)??(•?? ? ??•??)?_(___°π°œ)_「」°?|_|_=3( ´???` )*/ω\*)£"; [letters enumerateSubstringsInRange:NSMakeRange(0, [letters length]) options:(NSStringEnumerationByComposedCharacterSequences) usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { if ([string containsString:substring]) { NSLog(@"match character:%@",substring); isMatch = YES; *stop = YES; } }]; if (!isMatch) { NSString *pattern = @"[`~!@#$^&*()=|{}‘:;‘,\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“‘。,、?]+"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern]; isMatch = [pred evaluateWithObject:string]; } NSLog(@"%@ is SpecialCharacters:%d",string,isMatch);