作者:孟令文
#define NUMBERS @"0123456789."
- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string
{
if(textField ==self.textField05){
NSCharacterSet*cs;
cs = [[NSCharacterSetcharacterSetWithCharactersInString:NUMBERS]invertedSet];
NSString*filtered = [[stringcomponentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
BOOLbasicTest = [stringisEqualToString:filtered];
if(!basicTest) {
UIAlertView* alert = [[UIAlertViewalloc]initWithTitle:@"提示"
message:@"请输入数字"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertshow];
returnNO;
}
returnYES;
}
if(textField ==self.textField06){
NSCharacterSet*cs;
cs = [[NSCharacterSetcharacterSetWithCharactersInString:NUMBERS]invertedSet];
NSString*filtered = [[stringcomponentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
BOOLbasicTest = [stringisEqualToString:filtered];
if(!basicTest) {
UIAlertView* alert = [[UIAlertViewalloc]initWithTitle:@"提示"
message:@"请输入数字"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertshow];
returnNO;
}
returnYES;
}
returnYES;
}
网友评论