PDaria
PDaria

Reputation: 457

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?

Upvotes: 4

Views: 1795

Answers (1)

Gypsa
Gypsa

Reputation: 11314

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]];

Upvotes: 3

Related Questions