比如限制输入字符为ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@-_.
例子:
+(BOOL) isStringInCharacterSet:(NSString*) str (需要判断的字符串)
{
static NSString* s_strEmailChar = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@-_.";
NSCharacterSet* charset = [NSCharacterSet characterSetWithCharactersInString:s_strEmailChar];
NSCharacterSet* cs = [charSet invertedSet];
NSString *filtered = [[str componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [str isEqualToString:filtered];
}