YIem`s Blog -心比天高命比纸薄-链接找不到的请在站内搜索内容！ - UITextField
type: channel
link: https://www.yiem.net/tag/UITextField/
items: iOS输入框限制只能输入数字

iOS输入框限制只能输入数字
type: item
date: 2019-02-15T10:03:00+08:00
description: iOS输入框限制只能输入数字iOS输入框限制只能输入数字 代码- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { return [self validateNumber:string]; } - (BOOL)validateNumber:(NSString*)number { BOOL res = YES; NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; int i = 0; while (i < number.length) { NSString * string = [number substringWithRange:NSMakeRange(i, 1)]; NSRange range = [string rangeOfCharacterFromSet:tmpSet]; if (range.length == 0) { res = NO; break; } i++; } return res; }关于文章“iOS输入框限制只能输入数字”文章转载自：简书@Young_Blood 原文链接：https://www.jianshu.com/p/1bb9af3d3ad1