正则表达式Check Email

package usefull;

import java.util.regex.*;

public class CheckEmail {

public static void main(String[] args) {

System.out.println (checkmail(“www.@163.com“));
System.out.println (checkmail(“”));
System.out.println (checkmail(“”));
System.out.println (checkmail(“”));
System.out.println (checkmail(“”));
System.out.println (checkmail(“”));
System.out.println (checkmail(“www.@163.com_”));
System.out.println (checkmail(“”));
CheckEmail m = new CheckEmail();
m.check(“”);
System.out.println (CheckEmail.checkmail(“”));
}

public static boolean checkmail(String mail){
System.out.print (“Email地址:”+mail+” 合法性:”);//只为显示方便,正常使用时删除
//     使用正则表达式验证~
String regex = “^([a-z0-9A-Z]+[-|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$”;
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(mail);
return m.find();

}
public void check(String mail){
System.out.println (checkmail(mail));
}
}

 

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>