检测字符串中是否含有数字:
- (BOOL)containsDigit{ for (int i = 0; i < self.length; i++) { unichar c = [self characterAtIndex:i]; if((c > 47)&&(c < 58)) { return YES; } } return NO; }
检测字符串中是否含有特殊符号:
- (BOOL)containsSpecialCharacter{ NSString *specialCharacters = @"~`!@#$%^&*()_+-=[]|{};':\",.<>?/";//规定的特殊字符,可以自己随意添加 for (int i = 0; i < self.length; i++) { NSString *subStr = [self substringWithRange:NSMakeRange(i, 1)]; if([specialCharacters containsString:subStr]) { return YES; } } return NO; }