WEB开发网
开发学院WEB开发Jsp 用java实现简单的email正则表达式判断 阅读

用java实现简单的email正则表达式判断

 2008-01-05 09:38:50 来源:WEB开发网   
核心提示:import java.sql.*;import java.io.*;import java.util.regex.*;public class test{ public static void main(String[] args){ try{ String s = ""; while(

  import java.sql.*;
import java.io.*;
import java.util.regex.*;

public class test{
public static void main(String[] args){
try{
String s = "";
while(!s.equals("q")){
System.out.PRint("input:");
DataInputStream in = new DataInputStream(new BufferedInputStream(System.in));
s = in.readLine();
System.out.println("your input is :"+s);
String check = "^([a-z0-9A-Z]+[-\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(s);
boolean isMatched = matcher.matches();
if(isMatched){
System.out.println("it's a email");
}else{
System.out.println("it's not a email");
}

}
}catch(Exception e){
System.out.println("error"+e.getMessage());
}
}
}

Tags:java 实现 简单

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接