Possible Duplicate:
iphone how to check that a string is numeric only
I have one NSString, then i want check the string is number or not.
I mean
NSString *val = @"5555" ;
if(val isNumber ){
return true;
}else{
retun false;
}
How can I do this in Objective C?
Use
[NSNumberFormatter numberFromString: s]
. It returns nil if the specified string is non-numeric. You can configure the NSNumberFormatter to define "numeric" for your particular scenario.You could use
rangeOfCharacterFromSet:
: