62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.regex.*;
public class MailMatch
{
public static void main(String[] args)
{
String mailstring = "helloworld@163.com"; //要验证的字符串
String patter = "\\w+@\\w+.com"; //定义验证规则
Pattern p = Pattern.compile(patter); //实例化Pattern类
Matcher m = p.matcher(mailstring); //验证字符串是否合法
if(m.matches()){ //使用正则表达式
System.out.println("这个mail是合法的!");
}else{
System.out.println("这个mail是不合法的!");
}
}
}