android 检测手机号格式

时间:2022-07-11 19:05:19



public static boolean isPhone(Context mContext, String str) {

    if (!TextUtils.isEmpty(str)){

        Pattern pattern = Pattern.compile("^[0-9]{11}$");

        Matcher matcher = pattern.matcher(str);

        if (matcher.matches()) {

            Logger.t("AddressUtil").d("true");

            return true;

        } else {

            Logger.t("AddressUtil").d("false");

            return false;

        }

    }else{

        return false;

    }

}



public static boolean isPhone2(Context mContext,String str) {

    if (!TextUtils.isEmpty(str)){

        Pattern pattern = Pattern.compile("^1[3|4|5|7|8]{1}[0-9]{9}");

        Matcher matcher = pattern.matcher(str);

        if (matcher.matches()) {

            return true;

        } else {

            return false;

        }

    }else{

        return false;

    }

}