Check if NSString "000001XX"is a number with intValue
- by Kenny
Now I am trying to add a front end check on my app to detect if user input only number in the textfield.
I use:
- (IBAction)checkID:(UITextField *)sender {
if ([sender.text isEqualToString:@""]) {
sender.text = @"This information is required";
sender.backgroundColor =[UIColor redColor];
}else if (![sender.text intValue]) {
sender.text = [sender.text stringByAppendingString:@" is not valid number"];
sender.backgroundColor =[UIColor redColor];
}
NSLog(@"send.text is %@, intValue is %d",sender.text,[sender.text intValue]);
}
But I found it text begins with number and ends with string, its intValue is still the number.
In my text, text is "00001aa", but the intValue is 1.
Is there any other way to filter out this "00001aa" text?
Thanks in advance.