栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java的一些藏用正则表达式

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java的一些藏用正则表达式

static boolean flag = false;
    static String regex = "";

    public static boolean check(String str, String regex) {
        try {
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(str);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    
    public static boolean checkNotEmputy(String notEmputy) {
        regex = "^\s*$";
        return check(notEmputy, regex) ? false : true;
    }

    
    public static boolean checkEmail(String email) {
        // String regex = "^(\w+((-\w+)|(\.\w+))*)\+\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$";
        // return check(email, regex);
        Pattern pattern = Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$");
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();

    }

    
    public static boolean checkCellphone(String cellphone) {
        System.out.println("cellphone========"+cellphone);
        //联通好呐     130、131、132、145、155、156、166、171、175、176、185、186、196号。
        //移动手机号段  132 134 135 136 137 138 139 147 150 151 152 155 157 158 159 182 183 187 188
        //电信好吗号段  177,173,189,181,180,153,133,199
       // String regex ="^(13[0-9]|14[5|7]|16[6]|15[0|1|2|3|5|6|7|8|9]|17[1|3|5|6|7]|18[0|1|2|3|5|6|7|8|9]|19[9])\d{8}$";
        String regex = "^((13[0-9])|(14[5-9])|(15([0-3]|[5-9]))|(16[6-7])|(17[1-8])|(18[0-9])|(19[1|3])|(19[5|6])|(19[8|9]))\d{8}$";
        return check(cellphone, regex);
    }

    
    public static boolean checkTelephone(String telephone) {
        String regex = "^(0\d{2}-\d{8}(-\d{1,4})?)|(0\d{3}-\d{7,8}(-\d{1,4})?)$";
        return check(telephone, regex);
    }

    
    public static boolean checkFax(String fax) {
        String regex = "^(0\d{2}-\d{8}(-\d{1,4})?)|(0\d{3}-\d{7,8}(-\d{1,4})?)$";
        return check(fax, regex);
    }

    
    public static boolean checkQQ(String QQ) {
        String regex = "^[1-9][0-9]{4,} $";
        return check(QQ, regex);
    }

记录一下,主要做手机号的验证,更新时间2021-11-09

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/459994.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号