用java代码实现判断输入的字符串是合法的电子邮箱地址

时间:2025-03-10 08:16:19

用java代码实现判断输入的字符串是合法的电子邮箱地址

import ;
import ;
import ;


public class CheckEmail {

 
 public static void main(String[] args) throws IOException {
  String reg = "\\w+[\\w]*@[\\w]+\\.[\\w]+$";
  BufferedReader reader = new BufferedReader(new InputStreamReader());
  while(true){
   ("请输入要验证的邮箱地址:"+"\n"+"-->");
   String input = ();
   if(("q")||("exit")){
    (0);
   }
   if((reg)){
    ("这是正确的邮箱地址");
   }else{
    ("这是错误的邮箱地址 ");
   }
  }
 }

}