In my iPhone app I am trying to understand if a string is a valid number or not, the code below works most of the time but when I have a value starting with number and ends with text it wrongly returns “true” e.g “34rty”
if([[NSScanner scannerWithString:value] scanDouble:NULL] ){
val=[NSNumber numberWithDouble:[value doubleValue]];
}
what is wrong here?
scanDoublereturn via a reference.NSLog output:
You will have to scan up to the number if there is preceding text.
As @Benjamin says, a RegEx may be a better option for just checking.