Java mobile phone number attribution to the query

Source: Internet
Author: User
Tags i18n locale

According to the mobile phone number of the location, operators we refer to Google's Libphonenumber package, Libphonenumber is used to parse, format, store and verify the phone number of Java, C + + or JavaScript class library.

Dependent jar Packs: Com.googlecode.libphonenumber (Libphonenumber, Geocoder, Prefixmapper, Carrier)

Jar Package Download Address: Http://mvnrepository.com/search?q=libphonenumber (we can also use MAVEN configuration)

Package com.yuanzubao.common.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; /** * Cell Phone number attribution query * Dependent JAR package: Com.googlecode.libphonenumber (Libphonenumber, Geocoder, Prefixmapper, Carrier) * Developer: WANGQL * Development time Rooms: 2015-11-24 * */public class Phoneutil {private static phonenumberutil Phonenumberutil = Phonenumberutil.getinstan

    CE ();

    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 = Integer.valueof (CountryCode);

        Long phone = long.valueof (PhoneNumber);
        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 = integer.valueof (CountryCode);

        Long phone = long.valueof (PhoneNumber);
        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 = integer.valueof (CountryCode);
        
        Long phone = long.valueof (PhoneNumber);
        PhoneNumber pn = new PhoneNumber ();
        Pn.setcountrycode (Ccode);
        Pn.setnationalnumber (phone);
    Return Geocoder.getdescriptionfornumber (PN, Locale.chinese); }

}

Note: CountryCode is the country code, the mainland number is 86

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.