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

https://blog.csdn.net/zhang89xiao/article/details/51303056

合法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;    
    
/**  
 * 

    *    * 

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);      */     }     }     如何在插入数据库后返回增加的唯一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);

 

你可能感兴趣的:(java)