Java验证输入邮箱格式是否正确

时间:2022-11-05 17:09:07

package langu;

import java.util.Scanner;

public class 判断邮箱 {

public static void main(String[] args) {

Scanner scanner=new Scanner(System.in);
System.out.println("请输入邮箱:");
String s=scanner.next();

String reg="\\w+[@]{1}+[sina]{4}\\.com";//正则表达式,验证以新浪邮箱为例
if (s.matches(reg)) {
System.out.println("邮箱输入正确");
}else {
System.out.println("邮箱输入格式错误");
}
}

}