邮箱校验以及电话号码校验

[java]  view plain  copy
 print ?
  1. "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$"    
  2.     
  3. 这个是一个企业级的程序里copy出来的。    
[java]  view plain  copy
 print ?
  1. 合法E-mail地址:     
  2. 1. 必须包含一个并且只有一个符号“@”     
  3. 2. 第一个字符不得是“@”或者“.”     
  4. 3. 不允许出现“@.”或者.@     
  5. 4. 结尾不得是字符“@”或者“.”     
  6. 5. 允许“@”前的字符中出现“+”     
  7. 6. 不允许“+”在最前面,或者“+@”     
  8.     
  9. 正则表达式如下:     
  10. -----------------------------------------------------------------------     
  11. ^(\w+((-\w+)|(\.\w+))*)\+\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$     
  12. -----------------------------------------------------------------------     
  13.     
  14. 字符描述:     
  15. ^ :匹配输入的开始位置。     
  16. \:将下一个字符标记为特殊字符或字面值。     
  17. * :匹配前一个字符零次或几次。     
  18. + :匹配前一个字符一次或多次。     
  19. (pattern) 与模式匹配并记住匹配。     
  20. x|y:匹配 x 或 y。     
  21. [a-z] :表示某个范围内的字符。与指定区间内的任何字符匹配。     
  22. \w :与任何单词字符匹配,包括下划线。     
  23. $ :匹配输入的结尾。    
  24.     
  25. 参考资料:http://www.1-100.org/asp/2006/10273.htm    

[java]  view plain  copy
 print ?
  1. import java.util.regex.Matcher;    
  2. import java.util.regex.Pattern;    
  3.     
  4. /**  
  5.  * 

      

  6.  *  
  7.  * 

    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("[email protected]");    
  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. }    
  36. 如何在插入数据库后返回增加的唯一ID值 | encodeURIComponent编码后java后台的解码    


电话号码校验/包含固定号码(要带区号)
String regExp ="^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}|[0]{1}[0-9]{2,3}-[0-9]{7,8}$";
String num="15411753637";
Pattern pattern=Pattern.compile(regExp);
Matcher matcher=pattern.matcher(num);

你可能感兴趣的:(知识点)