Android常用的工具类判断电话,邮箱,汉字姓名等等

    xiaoxiao2021-12-14  17

    /** * 判断是否是合法手机号 * * @param mobiles * @return */ public static boolean isMobileNO(String mobiles) { String cm = "^1(34[0-8]|(3[5-9]|5[017-9]|8[278]|7[0-9])\\d)\\d{7}$";// 中国移动正则 String cu = "^1(3[0-2]|5[256]|8[56])\\d{8}$";// 中国联通正则 String ct = "^1((33|53|8[09])[0-9]|349)\\d{7}$";// 中国电信正则 if (Pattern.matches(cm, mobiles) || Pattern.matches(cu, mobiles) || Pattern.matches(ct, mobiles)) { return true; } return false; } /** * 验证输入的邮箱格式是否符合 * * @param email * @return 是否合法 */ public static boolean isEmail(String email) { String emailPattern = "[a-zA-Z0-9][a-zA-Z0-9._-]{2,16}[a-zA-Z0-9]@[a-zA-Z0-9]+.[a-zA-Z0-9]+"; boolean result = Pattern.matches(emailPattern, email); return result; } /** * 验证输入的用户名格式是否符合 ,长度为 3到16位的字符 * * @param username 只能是字母、数字、下划线、横杠 * @return 是否合法 */ public static boolean isUserName(String username) { String emailPattern = "^[a-zA-Z0-9_-]{3,16}$"; boolean result = Pattern.matches(emailPattern, username); return result; } /** * 验证输入的用户名格式是否符合 ,姓名必须是2到20位的汉字 * * @param username * @return 是否合法 */ public static boolean isChineseName(String name) { String emailPattern = "^[\u4e00-\u9fa5]{2,20}$"; boolean result = Pattern.matches(emailPattern, name); return result; } /** * 验证用户输入的是否是有效的数字 >=0.01 * * */ public static boolean isValidFloat(String f) { boolean isfloat = false; try { float ff = Float.parseFloat(f); if (ff >= 0.01f) { isfloat = true; } } catch (NumberFormatException nfEx) { } catch (Exception ex) { } return isfloat; }

    附:手机相关PhoneUtil类 开发工具类

    转载请注明原文地址: https://ju.6miu.com/read-964997.html

    最新回复(0)