android 檢測手機號格式
阿新 • • 發佈:2019-01-25
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; } }