iOS textField输入密码时需要实时判断输入的内容的类型,反馈给用户只能输入规定的数字或字母组合,比如只能输入int数字和_字母,可以用如下方法,非常简便
NSCharacterSet *s = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"];
s = [s invertedSet];
NSRange r = [string rangeOfCharacterFromSet:s];if (r.location !=NSNotFound) { NSLog(@"the string contains illegal characters");}
非常简便