oc中特殊字符的判断方法

-(BOOL)isSpacesExists

{

    //    NSString *_string = [NSString stringWithFormat:@"123 456"];

    NSRange _range = [self rangeOfString:@" "];

    if (_range.location != NSNotFound) {

        //有空格

        return YES;

    }else

    {        //没有空格

        return NO;

    }

}

-(BOOL)isSpecialCharacters

{

    NSCharacterSet *ValidCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"] invertedSet];

    NSRange Range = [self rangeOfCharacterFromSet:ValidCharacters];

    if (Range.location != NSNotFound)

    {

        NSLog(@"包含特殊字符");

    }

    return Range.location!=NSNotFound;

}


你可能感兴趣的:(oc中特殊字符的判断方法)