`
fatherican
  • 浏览: 48910 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Java邮箱正则表达式

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

    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); 
     
    */  
    }  
    }  
    如何在插入数据库后返回增加的唯一ID值 | encodeURIComponent编码后java后台的解码  


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics