lixing 4 лет назад
Родитель
Сommit
a8fbe27c0e

+ 15 - 1
fm-common/src/main/java/com/persagy/fm/common/constant/RegexConstants.java

@@ -1,5 +1,8 @@
 package com.persagy.fm.common.constant;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  * 正则表达式常量
  *
@@ -35,7 +38,7 @@ public class RegexConstants {
     /**
      * 所有允许的特殊字符正则表达式
      */
-    private static final String ALL_CHAR_REGEX = "[!\"#\\$%&'\\(\\)\\*\\+,-\\.\\/:;<=>\\?@\\[\\\\\\]\\^\\\\`\\{\\|\\}~\\s]";
+    private static final String ALL_CHAR_REGEX = "[!\"#\\$%&'\\(\\)\\*\\+,-\\.\\/:;<=>\\?@\\[\\\\\\]\\^_`\\{\\|\\}~\\s]";
 
     private static final String EN_REGEX_EXPRESSION = LOWERCASE_REGEX + "|" + UPPERCASE_REGEX;
     private static final String EN_NUM_REGEX_EXPRESSION = EN_REGEX_EXPRESSION + "|" + NUM_REGEX;
@@ -131,4 +134,15 @@ public class RegexConstants {
      * 手机号非法提示
      */
     public static final String PHONE_REGEX_WARNING = "请输入正确手机号码";
+
+    public static void main(String[] args) {
+        String str = "zhang`._#~]";
+        String regEx = ALL_REGEX;
+        // 编译正则表达式
+        Pattern pattern = Pattern.compile(regEx);
+        Matcher matcher = pattern.matcher(str);
+        // 字符串是否与正则表达式相匹配
+        boolean rs = matcher.matches();
+        System.out.println(rs);
+    }
 }