`

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("dffdfdf@qq.com");
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);

*/
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics