java验证手机号码是否合法
公司开发新功能须要验证手机号码,遂自己写了个出来,暂仅仅支持中国大陆手机号验证。如有不妥之处,还望大家指教,感激不尽!
/** * 验证是否是正确合法的手机号码 * * @param telephone * 须要验证的打手机号码 * @return 合法返回true,不合法返回false * */ public static boolean isCellPhoneNo(String telephone) { if (Common.empty(telephone)) { return false; } if (telephone.length() != 11) { return false; } Pattern pattern = Pattern.compile("^1[3,5]\\d{9}||18[6,8,9]\\d{8}$"); Matcher matcher = pattern.matcher(telephone); if (matcher.matches()) { return true; } return false; }