标签:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ return [self validNum:string]; } //限制只能输入数字 - (BOOL)validNum:(NSString*)number{ BOOL res = YES; NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; for (int i = 0; i < number.length; i ++) { NSRange subRanger = NSMakeRange(i , 1); NSString *subStr = [number substringWithRange:subRanger]; NSRange setRange = [subStr rangeOfCharacterFromSet:set]; if (setRange.length == 0) { res = NO; break; } } return res; }
标签:
原文地址:http://www.cnblogs.com/cnman/p/5167713.html