Java正则表达式验证电子邮箱地址、电话号码

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>
 *
 * <p>Copyright the original author or authors.
 *
 * @author Liu Huibin
 * @date Aug 27, 2010
 * @dateLastModified Aug 27, 2010
 */
public class Test {
public static void main(String[] args) {

//电子邮件
 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("[email protected]");
 boolean isMatched = matcher.matches();
 System.out.println(isMatched);

 

/* 电话号码

String check = "^(13[4,5,6,7,8,9]|15[0,8,9,1,7]|188|187)\\d{8}$";
 Pattern regex = Pattern.compile(check);
 Matcher matcher = regex.matcher("13555655606");
 boolean isMatched = matcher.matches();
 System.out.println(isMatched);

*/
}
}

你可能感兴趣的:(java,正则表达式,qq)