diff --git a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/RegexConsts.java b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/RegexConsts.java
deleted file mode 100644
index a34c436..0000000
--- a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/constant/RegexConsts.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package xyz.zhouxy.plusone.constant;
-
-/**
- * 正则表达式常量
- *
- * @author ZhouXY
- */
-public final class RegexConsts {
-
- public static final String DATE = "^\\d{4}-\\d{2}-\\d{2}";
-
- public static final String PASSWORD = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[\\w\\\\!#$%&'*\\+\\-/=?^`{|}~@\\(\\)\\[\\]\",\\.;':><]{8,32}$";
-
- public static final String CAPTCHA = "^[0-9A-Za-z]{4,6}$";
-
- public static final String EMAIL = "^\\w+([-+.]\\w+)*@[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})*(\\.(?![0-9]+$)[a-zA-Z0-9][-0-9A-Za-z]{0,62})$";
-
- public static final String MOBILE_PHONE = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
-
- public static final String USERNAME = "^[\\da-zA-Z_.@\\\\]{4,36}$";
-
- public static final String NICKNAME = "^[\\da-zA-Z_.@\\\\]{4,36}$";
-
- private RegexConsts() {
- throw new IllegalStateException("Utility class");
- }
-}
diff --git a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/ValidatableStringRecord.java b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/ValidatableStringRecord.java
index 37151a2..0a03e65 100644
--- a/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/ValidatableStringRecord.java
+++ b/plusone-basic/plusone-basic-domain/src/main/java/xyz/zhouxy/plusone/domain/ValidatableStringRecord.java
@@ -1,6 +1,7 @@
package xyz.zhouxy.plusone.domain;
import java.util.Optional;
+import java.util.regex.Pattern;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
@@ -13,15 +14,15 @@ import com.fasterxml.jackson.annotation.JsonValue;
public abstract class ValidatableStringRecord implements IValueObject {
protected String value;
- protected final String format;
+ protected final Pattern format;
- protected ValidatableStringRecord(String format) {
+ protected ValidatableStringRecord(Pattern format) {
this.format = format;
}
@JsonIgnore
protected boolean isValid() {
- return value.matches(format);
+ return format.matcher(value).matches();
}
@JsonValue
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalType.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalType.java
index 14022c7..5db3ded 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalType.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalType.java
@@ -1,18 +1,20 @@
package xyz.zhouxy.plusone.system.application.common.util;
+import java.util.regex.Pattern;
+
import lombok.Getter;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
public enum PrincipalType {
- EMAIL(RegexConsts.EMAIL),
- MOBILE_PHONE(RegexConsts.MOBILE_PHONE),
- USERNAME(RegexConsts.USERNAME)
+ EMAIL(PatternConsts.EMAIL),
+ MOBILE_PHONE(PatternConsts.MOBILE_PHONE),
+ USERNAME(PatternConsts.USERNAME)
;
@Getter
- private final String regex;
+ private final Pattern regex;
- PrincipalType(String regex) {
+ PrincipalType(Pattern regex) {
this.regex = regex;
}
}
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalUtil.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalUtil.java
index 96d3715..fef5125 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalUtil.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/common/util/PrincipalUtil.java
@@ -30,7 +30,7 @@ public class PrincipalUtil {
}
PrincipalType[] principalTypes = PrincipalType.values();
for (var principalType : principalTypes) {
- if (principal.matches(principalType.getRegex())) {
+ if (principalType.getRegex().matcher(principal).matches()) {
return principalType;
}
}
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateAccountCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateAccountCommand.java
index c2b09d6..be7f4fb 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateAccountCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/CreateAccountCommand.java
@@ -10,7 +10,7 @@ import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.URL;
import lombok.Data;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.RegexConsts;
import xyz.zhouxy.plusone.domain.ICommand;
import xyz.zhouxy.plusone.system.domain.model.account.AccountStatus;
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java
index 266016b..0a4409a 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/RegisterAccountCommand.java
@@ -4,7 +4,7 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import lombok.Data;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.RegexConsts;
import xyz.zhouxy.plusone.domain.ICommand;
/**
diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateAccountCommand.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateAccountCommand.java
index e45750c..cbfd6a9 100644
--- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateAccountCommand.java
+++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/command/UpdateAccountCommand.java
@@ -6,7 +6,7 @@ import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.URL;
import lombok.Data;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.RegexConsts;
import xyz.zhouxy.plusone.domain.ICommand;
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Email.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Email.java
index f09d3b7..fe12230 100644
--- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Email.java
+++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Email.java
@@ -1,9 +1,10 @@
package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.Objects;
+import java.util.regex.Pattern;
import cn.hutool.core.util.DesensitizedUtil;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
/**
* 值对象:电子邮箱地址
@@ -12,7 +13,7 @@ import xyz.zhouxy.plusone.constant.RegexConsts;
*/
public class Email extends Principal {
- public static final String REGEX = RegexConsts.EMAIL;
+ public static final Pattern REGEX = PatternConsts.EMAIL;
private Email(String email) {
super(REGEX);
diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/MobilePhone.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/MobilePhone.java
index ebf5b2e..c641536 100644
--- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/MobilePhone.java
+++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/MobilePhone.java
@@ -1,9 +1,10 @@
package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.Objects;
+import java.util.regex.Pattern;
import cn.hutool.core.util.DesensitizedUtil;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
/**
* 值对象:手机号码
@@ -12,7 +13,7 @@ import xyz.zhouxy.plusone.constant.RegexConsts;
*/
public class MobilePhone extends Principal {
- public static final String REGEX = RegexConsts.MOBILE_PHONE;
+ public static final Pattern REGEX = PatternConsts.MOBILE_PHONE;
private MobilePhone(String mobilePhone) {
super(REGEX);
diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Nickname.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Nickname.java
index 7fcd33a..0d09911 100644
--- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Nickname.java
+++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Nickname.java
@@ -1,8 +1,9 @@
package xyz.zhouxy.plusone.system.domain.model.account;
import java.util.Objects;
+import java.util.regex.Pattern;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
/**
@@ -12,7 +13,7 @@ import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
*/
public class Nickname extends ValidatableStringRecord {
- public static final String REGEX = RegexConsts.NICKNAME;
+ public static final Pattern REGEX = PatternConsts.NICKNAME;
private Nickname(String value) {
super(REGEX);
diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java
index 2e1b7bd..d810c58 100644
--- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java
+++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java
@@ -7,8 +7,8 @@ import javax.annotation.Nonnull;
import org.springframework.util.Assert;
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
-import xyz.zhouxy.plusone.constant.RegexConsts;
import xyz.zhouxy.plusone.domain.IValueObject;
import xyz.zhouxy.plusone.exception.BizException;
import xyz.zhouxy.plusone.system.util.PasswordUtil;
@@ -20,7 +20,7 @@ import xyz.zhouxy.plusone.system.util.PasswordUtil;
*/
public class Password implements IValueObject {
- private static final Pattern PATTERN = Pattern.compile(RegexConsts.PASSWORD);
+ private static final Pattern PATTERN = PatternConsts.PASSWORD;
private static final String DEFAULT_PASSWORD = "A1b2C3d4";
@Nonnull
diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Principal.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Principal.java
index b622630..c4a4701 100644
--- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Principal.java
+++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Principal.java
@@ -1,5 +1,7 @@
package xyz.zhouxy.plusone.system.domain.model.account;
+import java.util.regex.Pattern;
+
import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
/**
@@ -8,7 +10,7 @@ import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
* @author ZhouXY
*/
public abstract class Principal extends ValidatableStringRecord {
- protected Principal(String format) {
+ protected Principal(Pattern format) {
super(format);
}
}
diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Username.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Username.java
index 94eab93..530144f 100644
--- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Username.java
+++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Username.java
@@ -1,6 +1,8 @@
package xyz.zhouxy.plusone.system.domain.model.account;
-import xyz.zhouxy.plusone.constant.RegexConsts;
+import java.util.regex.Pattern;
+
+import xyz.zhouxy.plusone.commons.constant.PatternConsts;
/**
* 值对象:用户名
@@ -9,7 +11,7 @@ import xyz.zhouxy.plusone.constant.RegexConsts;
*/
public class Username extends Principal {
- public static final String REGEX = RegexConsts.USERNAME;
+ public static final Pattern REGEX = PatternConsts.USERNAME;
private Username(String username) {
super(REGEX);