java 手机号本地验证归属地

1. http://repo1.maven.org/maven2/com/googlecode/libphonenumber/

下载依赖包:carrier-1.9.jar  geocoder-2.32.jar  libphonenumber-7.2.2.jar  prefixmapper-2.32.jar

/**查询手机归属地*/
    public static boolean checkPhone(String tel, String _city) {
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        PhoneNumberOfflineGeocoder phoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance();
        String language ="CN";
        Phonenumber.PhoneNumber referencePhonenumber = null;
        try {
            referencePhonenumber = phoneUtil.parse(tel, language);
        } catch (NumberParseException e) {
            e.printStackTrace();
        }
//手机号码归属城市 city
        String city= phoneNumberOfflineGeocoder.getDescriptionForNumber(referencePhonenumber,Locale.CHINA);
        return city.equals(_city);
    }

 

posted on 2019-04-17 11:39  3137102247  阅读(894)  评论(0编辑  收藏  举报

导航