JAVA 判断号码是手机还是固话

兄弟们帮我说下,JAVA 判断号码是手机还是固话
最新回答
晨曦慕雪

2024-05-15 16:09:43

/**
* 验证是否是手机号码
*
* @param str
* @return
*/
public static boolean isPhone(String str) {
if (ValidationUtils.isEmpty(str)) {
return false;
}
Pattern pattern = Pattern.compile("^(1[3,4,5,7,8][0-9])\\d{8}$");
Matcher matcher = pattern.matcher(str);
boolean b = matcher.matches();
return b;
}
/**
* 是否是
座机
电话号码
*
* @param str
* @return
*/
public static boolean isFixedLine(String str) {
if (ValidationUtils.isEmpty(str)) {
return false;
}
Pattern pattern = Pattern
.compile("^([0-9]{3}-?[0-9]{8})|([0-9]{4}-?[0-9]{7})$");
Matcher matcher = pattern.matcher(str);
boolean b = matcher.matches();
return b;
}