public static void main(String args[]){
String regex1="0\\d{2,3}[-]?\\d{7,8}|0\\d{2,3}\\s?\\d{7,8}";
String regex2="1[3-9][0-9]\\d{8}";
Scanner scan=new Scanner(System.in);
String answer;
do{
System.out.print("请输入您的号码: ");
String phone=scan.next();
//定义Pattern对象
Pattern pattern1=Pattern.compile(regex1);
Pattern pattern2=Pattern.compile(regex2);
//匹配对象
Matcher matcher1=pattern1.matcher(phone);
Matcher matcher2=pattern2.matcher(phone);
//bool函数判断输入是否正确
boolean boo1=matcher1.matches();
boolean boo2=matcher2.matches();
if(boo1)
System.out.println("您输入的是电话号码:\n"+phone);
else if(boo2)
System.out.println("您输入的是手机号码:\n"+phone);
else
System.out.println("格式错误:\n");
System.out.println("是否重新输入?(是/否)");
answer=scan.next();
}while(answer.equalsIgnoreCase("是"));
}
}