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

来源:互联网 发布:python的pow方法 编辑:程序博客网 时间:2024/04/28 13:48


转自:http://blog.csdn.net/gao_chun/article/details/39580363?utm_source=tuicool&utm_medium=referral

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 plain copyprint?在CODE上查看代码片派生到我的代码片    public static boolean isMobileNO(String mobiles){                Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");                Matcher m = p.matcher(mobiles);                  return m.matches();                }  



第二种方法:

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




java-正则表达式判断 邮编

中国邮政编码为6位数字,第一位不为0
[java] view plain copy print?在CODE上查看代码片派生到我的代码片    String str = "^[1-9][0-9]{5}$";       /**         * 判断邮编         * @param paramString         * @return         */         public static boolean isZipNO(String zipString){             String str = "^[1-9][0-9]{5}$";             return Pattern.compile(str).matcher(zipString).matches();         }  




java-正则表达式判断 Email邮箱 是否合法
[java] view plain copy print?在CODE上查看代码片派生到我的代码片    /**         * 判断邮箱是否合法         * @param email         * @return         */         public static boolean isEmail(String email){               if (null==email || "".equals(email)) return false;                 //Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配               Pattern p =  Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//复杂匹配               Matcher m = p.matcher(email);               return m.matches();           }   


QQ号

 public static boolean isQQCorrect(String str) {  String  regex ="[1-9][0-9]{4,14}";  Pattern p = Pattern.compile(regex);   Matcher m = p.matcher(str);   return m.matches();    } 


0 0
原创粉丝点击