加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

一些格式的Java工具类

发布时间:2020-12-14 23:18:00 所属栏目:Java 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 public class FormatTools { /** * 判断邮箱 * * @param email * @return */ public static boolean isEmail(String email) { String str = "^([a-zA-

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

    public class FormatTools {  
        /** 
         * 判断邮箱 
         *  
         * @param email 
         * @return 
         */  
        public static boolean isEmail(String email) {  
            String str = "^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$";  
            Pattern p = Pattern.compile(str);  
            Matcher m = p.matcher(email);  
      
            return m.matches();  
        }  
      
        // 判断手机号  
        public static boolean IsPhoneNum(String mobiles) {  
            if (mobiles.trim().length() == 11) {  
                Pattern p = Pattern  
                        .compile("^((13[0-9])|(15[^4,D])|(18[0,2,5-9]))d{8}$");  
                Matcher m = p.matcher(mobiles);  
                Log.d("IsPhoneNum",m.matches() + "");  
                return m.matches();  
            }  
            return false;  
      
        }  
      
        // 判断座机  
        public static boolean IsCallNum(String mobiles) {  
            boolean isValid = false;  
            CharSequence inputStr = mobiles;  
            Pattern pattern = Pattern.compile("^(0d{2,3})(d{7,8})(d{3,})?$");  
            Matcher matcher = pattern.matcher(inputStr);  
            if (matcher.matches()) {  
                isValid = true;  
            }  
            return isValid;  
        }  
      
        // 判断手机或座机  
        public static boolean IsAllCallNum(String mobiles) {  
            boolean isValid = false;  
            String expression = "(^((13[0-9])|(15[^4,5-9]))d{8}$)|"  
                    + "(^(0d{2,})?$)";  
            CharSequence inputStr = mobiles;  
            Pattern pattern = Pattern.compile(expression);  
            Matcher matcher = pattern.matcher(inputStr);  
            if (matcher.matches()) {  
                isValid = true;  
            }  
            return isValid;  
        }  
      
        // 判断字符串是数字  
        public static boolean isNumeric(String str) {  
            for (int i = 0; i < str.length(); i++) {  
                // System.out.println(str.charAt(i));  
                if (!Character.isDigit(str.charAt(i))) {  
                    return false;  
                }  
            }  
            return true;  
        }  
      
        /** 
         * 判断是否为整数 
         *  
         * @param str 传入的字符串 
         *  
         * @return 是整数返回true,否则返回false 
         */  
      
        public static boolean isInteger(String str) {  
            Pattern pattern = Pattern.compile("^[-+]?[d]*$");  
            return pattern.matcher(str).matches();  
        }  
      
        /** 
         * 判断是否符合密码规则 
         *  6-16为字母数字集合 不包含非法字符 
         * @param str 
         * @return 
         */  
        public static boolean isPwd(String str) {  
            Pattern pattern = Pattern.compile("^[a-z0-9A-Z]+$");  
            return pattern.matcher(str).matches();  
        }  
      
        /** 
         * 将秒转换成小时分钟 
         *  
         * @param second 
         * @return 
         */  
        public static String changeTotime(int second) {  
            int h = 0;  
            int d = 0;  
            int s = 0;  
            int temp = second % 3600;  
            if (second > 3600) {  
                h = second / 3600;  
                if (temp != 0) {  
                    if (temp > 60) {  
                        d = temp / 60;  
                        if (temp % 60 != 0) {  
                            s = temp % 60;  
                        }  
                    } else {  
                        s = temp;  
                    }  
                }  
            } else {  
                d = second / 60;  
                if (second % 60 != 0) {  
                    s = second % 60;  
                }  
            }  
      
            // return h + "小时" + d + "分钟" + s + "秒";  
            return h + "小时" + d + "分钟";  
        }  
      
        /** 
         * 米转换成公里 
         *  
         * @return 
         */  
        public static String miToGl(int distance) {  
            double dis = Math.round(distance / 100d) / 10d;  
            return dis + "公里";  
        }  
    }  

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读