/** * 判断传入的字符串是否是一个手机号码 * * @param strPhone * @return */ public static boolean isPhoneNumber(String strPhone) { String str = "^((13[0-9])|(15[^4,\\D])|(18[0-9])|(17[0-9])|(14[0-9]))\\d{8}$"; Pattern p = Pattern.compile(str); Matcher m = p.matcher(strPhone); return m.find(); } /** * 判断传入的字符串是否是一个电话号码或手机号码 * * @param strPhone * @return */ public static boolean isLandlineNumber(String strPhone) { String str = "^0\\d{2,3}-?\\d{7,8}$|^(13[0-9]|15[0-9]|18[0-9]|14[0-9]|17[0-9])\\d{8}$"; Pattern p = Pattern.compile(str); Matcher m = p.matcher(strPhone); return m.find(); }
正则表达式判断是否是手机号,或电话号码
最新推荐文章于 2025-09-22 21:04:07 发布
本文提供了两个实用的方法:一是用于验证输入的字符串是否符合中国大陆手机号码的标准格式;二是验证输入的字符串是否为电话号码或手机号码,适用于多种格式。通过正则表达式匹配的方式进行检查。
859

被折叠的 条评论
为什么被折叠?



