Java常用正则表达式

验证规则通用方法:
public static boolean regexJudge(String regex, String param) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(param);
        if (matcher.matches()) {
            return true;
        }
        return false;
    }

用法:直接调用上面方法regexJudge()

验证密码 :6-20位 必须包含 字母+数字:
       String regex = "^(?=.*[0-9])(?=.*[a-zA-Z])(.{6,20})$";

验证是否是纯数字:
       String reg = "^\\d+$";

验证手机号:
       String reg = "^[1][3,4,5,7,8,9][0-9]{9}$";

你可能感兴趣的:(开发问题总览)