谓词: NSPredicate
-
1.比较操作
-
2.字符串常规操作
-
3.范围
-
4.通配符
-
5.逻辑运算符
-
6.正则表达式
-
判断是不是字母,判断是不是数字,判断是是不是字母和数字
// If my string contains ony letters - (BOOL)containsOnlyLetters { NSCharacterSet *letterCharacterset = [[NSCharacterSet letterCharacterSet] invertedSet]; return ([self rangeOfCharacterFromSet:letterCharacterset].location == NSNotFound); } // If my string contains only numbers - (BOOL)containsOnlyNumbers { NSCharacterSet *numbersCharacterSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet]; return ([self rangeOfCharacterFromSet:numbersCharacterSet].location == NSNotFound); } // If my string contains letters and numbers - (BOOL)containsOnlyNumbersAndLetters { NSCharacterSet *numAndLetterCharSet = [[NSCharacterSet alphanumericCharacterSet] invertedSet]; return ([self rangeOfCharacterFromSet:numAndLetterCharSet].location == NSNotFound); } 复制代码