Check if NSString "000001XX"is a number with intValue
Posted
by
Kenny
on Stack Overflow
See other posts from Stack Overflow
or by Kenny
Published on 2012-08-29T03:21:33Z
Indexed on
2012/08/29
3:38 UTC
Read the original article
Hit count: 160
nsstring
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.
© Stack Overflow or respective owner