Phone number normalization: Any pre-existing libraries?

前端 未结 5 1045
不知归路
不知归路 2021-02-05 07:35

I have a system which is using phone numbers as unique identifiers. For this reason, I want to format all phone numbers as they come in using a normalized format. Because I have

5条回答
  •  无人共我
    2021-02-05 08:34

    You could use libphonenumber from Google. Here's a blog post:

    http://blog.appharbor.com/2012/02/03/net-phone-number-validation-with-google-libphonenumber

    Parsing numbers is as easy as installing the NuGet package and then doing this:

    var util = PhoneNumberUtil.GetInstance();
    var number = util.Parse("555-555-5555", "US");
    

    You can then format the number like this:

    util.Format(number, PhoneNumberFormat.E164);
    

    libphonenumber supports several formats other than E.164.

提交回复
热议问题