禁止UITextField输入数字 :
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
return [selfvalidateNumber:string];
}
- (BOOL)validateNumber:(NSString*)number {
BOOL res =YES;
NSCharacterSet* tmpSet = [NSCharacterSetcharacterSetWithCharactersInString:@"0123456789"];
int i =0;
while (i < number.length) {
NSString * string = [numbersubstringWithRange:NSMakeRange(i,1)];
NSRange range = [stringrangeOfCharacterFromSet:tmpSet];
if (range.length ==0) {
res = NO;
break;
}
i++;
}
return res;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
returntrue;
}