比如限制输入字符为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];
}
posted on 2013-07-24 18:04  童话DY  阅读(422)  评论(0编辑  收藏  举报