android 判断 手机号码、邮编、Email邮箱、是否正确

来源:互联网 发布:淘宝申请售后时间限制 编辑:程序博客网 时间:2024/04/28 13:54

转自:http://blog.csdn.net/gao_chun/article/details/39580363

java-正则表达式判断手机号


要更加准确的匹配手机号码只匹配11位数字是不够的,比如说就没有以144开始的号码段,

故先要整清楚现在已经开放了多少个号码段,国家号码段分配如下:

移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188

联通:130、131、132、152、155、156、185、186

电信:133、153、180、189、(1349卫通)

那么现在就可以正则匹配测试了,

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. public static boolean isMobileNO(String mobiles){    
  2.   
  3.   Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");    
  4.   
  5.   Matcher m = p.matcher(mobiles);    
  6.   
  7.     return m.matches();    
  8.   
  9.   }   

第二种方法:

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. String value="手机号";    
  2.   
  3. String regExp = "^[1]([3][0-9]{1}|59|58|88|89)[0-9]{8}$";    
  4.   
  5. Pattern p = Pattern.compile(regExp);    
  6.   
  7. Matcher m = p.matcher(value);    
  8.   
  9.   return m.find();//boolean  



java-正则表达式判断 邮编

中国邮政编码为6位数字,第一位不为0

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. String str = "^[1-9][0-9]{5}$";  
  2.  /** 
  3.     * 判断邮编 
  4.     * @param paramString 
  5.     * @return 
  6.     */  
  7.    public static boolean isZipNO(String zipString){  
  8.        String str = "^[1-9][0-9]{5}$";  
  9.        return Pattern.compile(str).matcher(zipString).matches();  
  10.    }  



java-正则表达式判断 Email邮箱 是否合法


[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. /** 
  2.     * 判断邮箱是否合法 
  3.     * @param email 
  4.     * @return 
  5.     */  
  6.    public static boolean isEmail(String email){    
  7.        if (null==email || "".equals(email)) return false;      
  8.        //Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配    
  9.        Pattern p =  Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//复杂匹配    
  10.        Matcher m = p.matcher(email);    
  11.        return m.matches();    
  12.    }   

0 0