- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-/:;()$&@\".,?!'[]{}#%^*+=_'\'|~<>£¥.,?!'"] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
if (![string isEqualToString:filtered]) {
return NO;
}
NSString * inputString = [textField.text stringByReplacingCharactersInRange:range withString:string];
//输入密码超过16位 不让其再输入,密码8~16位
if (inputString.length > KPasswordMaxLength) {
textField.text = [inputString substringToIndex:KPasswordMaxLength];
}else{
textField.text = inputString;
}
return NO;
}