android – 从用户的地址簿中规范化电话号码的策略?

android – 从用户的地址簿中规范化电话号码的策略?,第1张

概述这是一个普遍的问题,但特别是在 Android和iPhone上影响我:给定一个用户和一个电话号码,我如何规范化该电话号码实际上对存储和拨号有用?用户可以在表单的地址簿中输入电话号码: > 7位数美国号码(555-1212) > 10位美国号码(210-555-1212) >国际号码(46-555-1212) >国内非美国全数(123-555-1212) >国内非美国截断数字(555-1212) 我 这是一个普遍的问题,但特别是在 Android和iPhone上影响我:给定一个用户和一个电话号码,我如何规范化该电话号码实际上对存储和拨号有用?用户可以在表单的地址簿中输入电话号码:

> 7位数美国号码(555-1212)
> 10位美国号码(210-555-1212)
>国际号码(46-555-1212)
>国内非美国全数(123-555-1212)
>国内非美国截断数字(555-1212)

我知道有关用户提交此号码的事项:

> IP地址
>也许是他们的电话号码
>也许他们选择的国家
>也许他们选择的地区

这似乎是一个棘手的问题 – 除非我真的需要,否则我绝对不想要求用户提供更多信息,但这些数据需要非常值得信赖.我可以在这里重复使用最佳实践吗?

解决方法 IOS

好的,这可能对你很有帮助.希望如此.

在我的应用程序中,我需要 – 以某种方式从联系人处获取电话号码.所以问题就在于你所解释的 – 可以使用各种 – *()字符,以及没有国家代码.

所以 – 我使用ABPeoplePickerNavigationController获取联系号码,并从数字真实数字和可能 – 国家代码使用函数得到:

- (voID)saveContactPhone:(Nsstring *) mContactPhone{    if(mContactPhone && [mContactPhone length])    {           if ([mContactPhone rangeOfString:@"+"].location != NSNotFound)//this means number includes country code.         {            Nsstring * mCCodeString = @"";            BOol mFound = FALSE;            for(int i = 0; i<[mContactPhone length]; i++) // check number for any obvIoUs country code.            {                if(mFound == TRUE)                {                    break;                }                mCCodeString = [mContactPhone substringToIndex:i];                mCCodeString = [[mCCodeString componentsSeparatedByCharactersInSet:                [[NSCharacterSet decimalDigitCharacterSet] invertedSet]]                 componentsJoinedByString:@""];                if([mCCodeString intValue] != 1)//because This is US/CA                {                    for(int j = 0; j<[pickerVIEwElementArray_ count]; j++)                    {                         if([[pickerVIEwElementArray_ objectAtIndex:j] intValue] == [mCCodeString intValue])                        {                            mFound = TRUE;                            //we got ourselves final telephone number                             //and we got country code!!                            mContactPhone = [mContactPhone substringFromIndex:i];                            break;                        }                    }                }            }            if(mFound == FALSE)//If no luck finding a match - lets try again,but til index 2. (find if it is +1)            {                mCCodeString = [mContactPhone substringToIndex:2];                mCCodeString = [[mCCodeString componentsSeparatedByCharactersInSet:                [[NSCharacterSet decimalDigitCharacterSet] invertedSet]]                 componentsJoinedByString:@""];                mContactPhone = [mContactPhone substringFromIndex:1];                for(int i = 0; i<[pickerVIEwElementArray_ count]; i++)                {                     if([[pickerVIEwElementArray_ objectAtIndex:i] intValue] == [mCCodeString intValue])                    {                           //we found it!! Its +1!!!!                        mFound = TRUE;                        break;                    }                }            }        }    }    mContactPhone = [[mContactPhone componentsSeparatedByCharactersInSet:            [[NSCharacterSet decimalDigitCharacterSet] invertedSet]]             componentsJoinedByString:@""];}

您还需要国家/地区代码数组:例如:

NSArray *pickerVIEwElementArray_ = [NSArray arrayWithObjects:     @"93",@"355",@"213",@"1684",@"376",@"244",....

希望能帮到别人!

总结

以上是内存溢出为你收集整理的android – 从用户的地址簿中规范化电话号码的策略?全部内容,希望文章能够帮你解决android – 从用户的地址簿中规范化电话号码的策略?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1124202.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存