简体   繁体   中英

How we show the International Phone Numbers format like as Contacts number format?

I like to show the international phone number on app screen like the format are used by Apple Contacts app(iPhone 6). For Example: +1 (xxx) xxx-xxxx, +91 xxxxx xxxxx, +61 (0) x xxxx xxxx, xxxxx xxxxx.

Can we deploy the standard Apple display of phone numbers format like how they arrange phone numbers in the iOS Contacts app.

Please give me some suggestion to proceed....

Is there any third party API is available to identify the number and return the number format like contact app number format. Please let me know...

I am waiting for your valuable response....

Thanks in Advance.

Please try this code:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    int groupingSize = 2;
    if([string length] == 0) {
        groupingSize = 4;
    }
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init] ;
    NSString *separator = @"-";
    [formatter setGroupingSeparator:separator];
    [formatter setGroupingSize:groupingSize];
    [formatter setUsesGroupingSeparator:YES];
    [formatter setSecondaryGroupingSize:2];
    if (![string  isEqual: @""] && (textField.text != nil && textField.text.length > 0)) {
        NSString *num = textField.text;
        num = [num stringByReplacingOccurrencesOfString:separator withString:@""];
        NSString *str = [formatter stringFromNumber:[NSNumber numberWithDouble:[num doubleValue]]];
        textField.text = str;
    }
    return YES;
}

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM