How do I check if a UITextField
's text is a double or not?
Simple validation required, if the entered textfield value is a valid double value or not?
Valid double values: 1.00
, 1.01
or 1.00001
Invalid double values: .0.1
, .001.11
, 1.0.1
or 1...0
etc.
mytxtfield.text=@"12.00"; //ok
mytxtfield.text=@"1.2..0"; // is invalid and so on
EDIT: My answer that works thanx sahzad ali
//------------
-(BOOL)isvalidDouble:(NSString*)txtstring
{
NSArray *dotSeparratedArray = [txtstring componentsSeparatedByString:@"."];
NSInteger count=[dotSeparratedArray count];
count=count-1;
if(count >1)
{
return TRUE ; //invalid
}
return FALSE; //valid
}