您的位置:首页 > 编程语言 > Java开发

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

2005-01-26 09:47 1081 查看
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());
}
}
}

作者Blog:http://blog.csdn.net/wumingwangzi/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: