Java⽤正则表达式验证⽤户输⼊的⼿机号和QQ邮箱import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//⽤正则验证⽤户输⼊的⼿机号和QQ邮箱
checkPhone();
checkEmail();
}
public static void checkEmail(){
Scanner sc = new Scanner(System.in);
2012年十二生肖运程while (true) {
System.out.println("请您输⼊您的注册邮箱:");
String email = sc.next();
李珉延
if(email.matches("\\w{1,30}@[a-zA-Z0-9]{2,20}(\\.[a-zA-Z0-9]{2,20}){1,2}")){
System.out.println("邮箱格式正确,注册完成!");
break;
}else {
金秀贤合约到期
System.out.println("格式有误!");
妩媚女网名
}
}
}
台州小舒淇public static void checkPhone(){
Scanner s=new Scanner(System.in);
System.out.println("请输⼊11为⼿机号码:");
String res= s.next();
//判断设⼿机号码格式是否正确
if (res.matches("1[3-9]\\d{9}")){
System.out.println("你的⼿机号码为:"+res);
}else{浅蓝配什么颜
System.out.println("你输⼊的⼿机号码不合法");
}
}
}