#define NUMBERS @"0123456789."
_contentTextFiled.delegate = self;
#pragma mark ---textfiled代理方法
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSCharacterSet*cs;
cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
BOOL basicTest = [string isEqualToString:filtered];
if (!basicTest) {
return NO;
}else {
return YES;
}
}
用以上代理方法可实现只能输入数字和小数点