电子邮箱和电话

来源:互联网 发布:国家文物局官网通知 编辑:程序博客网 时间:2024/04/28 13:45
  1. import java.util.regex.Matcher;    
  2. import java.util.regex.Pattern;    
  3.     
  4. /**  
  5.  * <p>  
  6.  *  
  7.  * <p>Copyright the original author or authors.  
  8.  *  
  9.  * @author Liu Huibin  
  10.  * @date Aug 27, 2010  
  11.  * @dateLastModified Aug 27, 2010  
  12.  */    
  13. public class Test {    
  14. public static void main(String[] args) {    
  15.     
  16. //电子邮件    
  17.  String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";    
  18.  Pattern regex = Pattern.compile(check);    
  19.  Matcher matcher = regex.matcher("dffdfdf@qq.com");    
  20.  boolean isMatched = matcher.matches();    
  21.  System.out.println(isMatched);    
  22.     
  23.      
  24.     
  25. /* 电话号码  
  26.   
  27. String check = "^(13[4,5,6,7,8,9]|15[0,8,9,1,7]|188|187)\\d{8}$";  
  28.  Pattern regex = Pattern.compile(check);  
  29.  Matcher matcher = regex.matcher("13555655606");  
  30.  boolean isMatched = matcher.matches();  
  31.  System.out.println(isMatched);  
  32.   
  33. */    
  34. }    
  35. }    
0 0
原创粉丝点击