用正则表达式校验邮箱
public class Demo1Zhengze {
public static void main(String[] args) {
String input = input();
if(check(input)){
System.out.println("恭喜登录成功!!!");
}
}
public static String input() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入帐号。。。");
String str = sc.next();
return str;
}
public static boolean check(String str) {
String regex = "^[a-zA-Z]\\w{0,30}@qq.com$";
Character tou = str.charAt(0);
String t = tou.toString();
Boolean b = false;
if (str.replaceAll("[a-z]*[A-Z]*\\d*-*_*\\s*[@qq.com]*", "").length() != 0) {
System.out.println("不能有特殊符号!");
return b;
} else if (t.matches("[0-9]")) {
System.out.println("不能以数字开头!!!");
return b;
} else if (str.matches(regex)) {
System.out.println("帐号符合要求!!!");
b = true;
return b;
} else {
System.out.println("帐号不正确!!!");
return b;
}
}
}