object-C 判断字符串是否含有特殊字符

 NSCharacterSet *nameCharacters = [[NSCharacterSet

  characterSetWithCharactersInString:@"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"] invertedSet];

NSRange userNameRange = [myString rangeOfCharacterFromSet:nameCharacters];

if (userNameRange.location != NSNotFound) {

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

}

你可能感兴趣的:(object-C 判断字符串是否含有特殊字符)