Mobile phone number belongs to the Libphonenumber

Source: Internet
Author: User
Tags i18n locale
Libphonenumber is a Google-developed common Java class Library for parsing, formatting, storing, and validating international phone numbers. Suitable for smartphones, while providing a JavaScript transplant. 

Give an example

Package com.lei.util;

Import Java.util.Locale;
Import Com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper;
Import Com.google.i18n.phonenumbers.PhoneNumberUtil;
Import Com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
Import Com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
Import Com.okcoin.util.StringUtil;
    /** code example Stringutil is a string tool class, not provided, and can be replaced. You can use the string native function to replace the/public class Phoneutil {private static phonenumberutil Phonenumberutil = Phonenumberutil.getin

    Stance ();

    private static Phonenumbertocarriermapper Carriermapper = Phonenumbertocarriermapper.getinstance ();

    private static Phonenumberofflinegeocoder Geocoder = Phonenumberofflinegeocoder.getinstance (); /** * According to the country code and cell phone number to determine whether the cell phone number is valid * @param phonenumber * @param countrycode * @return * * Public STA Tic Boolean Checkphonenumber (String PhoneNumber, string countrycode) {int ccode = Stringutil.tointeger (countrycod
        e); Long phone= Stringutil.tolong (PhoneNumber, 0L);
        PhoneNumber pn = new PhoneNumber ();
        Pn.setcountrycode (Ccode);

        Pn.setnationalnumber (phone);

    return Phonenumberutil.isvalidnumber (PN); /** * According to the country code and cell phone number to determine the mobile phone operator * @param phonenumber * @param * * * @return * * * * * * * * publi C Static String Getcarrier (String PhoneNumber, string countrycode) {int ccode = Stringutil.tointeger (CountryCode)
        ;

        Long phone = Stringutil.tolong (PhoneNumber, 0L);
        PhoneNumber pn = new PhoneNumber ();
        Pn.setcountrycode (Ccode);
        Pn.setnationalnumber (phone);
        Return result only in English, turn into Chinese String carrieren = carriermapper.getnamefornumber (pn, Locale.english);
        String Carrierzh = "";
        Carrierzh + = Geocoder.getdescriptionfornumber (pn, Locale.chinese);
            Switch (carrieren) {case "Carrierzh": + + = "mobile";
        Break Case "Unicom": Carrierzh+ = "Unicom";
        Break
            Case "Telecom": Carrierzh + + "telecom";
        Break
        Default:break;
    return Carrierzh; 
    /** * * @Description: According to the country code and mobile phone number of the home * @date 2015-7-13 11:33:18 * @param @param phonenumber * @param @param countrycode * @param @return parameter * @throws/public static string Getgeo (String p
        Honenumber, String countrycode) {int ccode = Stringutil.tointeger (CountryCode);

        Long phone = Stringutil.tolong (PhoneNumber, 0L);
        PhoneNumber pn = new PhoneNumber ();
        Pn.setcountrycode (Ccode);

        Pn.setnationalnumber (phone);

    Return Geocoder.getdescriptionfornumber (PN, Locale.chinese);

    public static void Main (string[] args) {System.out.println (Phoneutil.getcarrier ("159655555", "86")); }

}

Related Information
GitHub Address: Https://github.com/googlei18n/libphonenumber

MAVEN address
    <dependency>
        <groupId>com.googlecode.libphonenumber</groupId>
        < artifactid>libphonenumber</artifactid>
        <version>7.0</version>
    </dependency>
    <dependency>
      <groupId>com.googlecode.libphonenumber</groupId>
      <artifactid >carrier</artifactId>
      <version>1.11</version>
    </dependency>
    < dependency>
        <groupId>com.googlecode.libphonenumber</groupId>
        <artifactId> geocoder</artifactid>
        <version>2.12</version>
    </dependency>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.