Regex to match all us phone number formats

后端 未结 7 791
借酒劲吻你
借酒劲吻你 2020-12-03 03:32

First of all i would say i have seen many example here and googled but none found that matches all the condition i am looking for some match top 3 not below some inbetween.

7条回答
  •  一个人的身影
    2020-12-03 04:14

    Help yourself. Dont use a regex for this. Google release a great library to handle this specific use case: libphonenumber. There is an online demo of the lib.

    public static void Main()
    {
        var phoneUtil = PhoneNumberUtil.GetInstance();
        var numberProto = phoneUtil.Parse("(979) 778-0978", "US");
        var formattedPhone = phoneUtil.Format(numberProto, PhoneNumberFormat.INTERNATIONAL);
        Console.WriteLine(formattedPhone);
    }
    

    Demo on .NETFiddle

提交回复
热议问题