Search code examples
iosiphoneformattingphone-numberphone-call

phone number format for iPhone


I have to make calls programmatically in my iPhone app. I have set of numbers in different countries with different formatting - braces, dots, spaces, "+" sign.

Can I simply remove all of this and left only numbers?

for example:

+1-(609) 452-8401 => 16094528401 // usa
+49(0)89.439 => 49089439 // germany
+1-(949)586-1250 => 19495861250 // los angeles, usa

Will it be correct?


Solution

  • try this:-

    NSMutableString *str1=[[NSMutableString alloc] initWithString:telephoneString];
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"(" withString:@""]];
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@")" withString:@""]];
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"-" withString:@""]];
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@" " withString:@""]];
    telephoneString = [@"tel://" stringByAppendingString:str1];
    [str1 release];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telephoneString]];