import java.util.Scanner;
public class TelephoneNumber {
Scanner sc = new Scanner(System.in);
public void verify(){
System.out.println("请输入手机号码:");
while(true){
String telNumber = sc.next();
String phoneRegex = "[1][3,4,5,7,8][0-9]{9}";
if(!telNumber.matches(phoneRegex)) {
System.out.println("您输入的手机号码格式不正确!请重新输入!");
continue;
}else{
System.out.println("您输入的手机号码符合要求!");
break;
}
}
}
}
public class Test {
public static void main(String[] args){
TelephoneNumber tn = new TelephoneNumber();
tn.verify();
}
}
|
|