使用 RegexUtil 做正则校验。

This commit is contained in:
zhouxy108 2023-06-29 01:18:08 +08:00
parent 13fc8e40b5
commit 672a16ad19

View File

@ -21,6 +21,7 @@ import java.util.regex.Pattern;
import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.annotation.JsonValue;
import xyz.zhouxy.plusone.commons.util.Assert; import xyz.zhouxy.plusone.commons.util.Assert;
import xyz.zhouxy.plusone.commons.util.RegexUtil;
/** /**
* 带校验的字符串值对象 * 带校验的字符串值对象
@ -34,7 +35,7 @@ public abstract class ValidatableStringRecord {
protected ValidatableStringRecord(String value, Pattern pattern) { protected ValidatableStringRecord(String value, Pattern pattern) {
Assert.notNull(pattern, "The pattern must not be null."); Assert.notNull(pattern, "The pattern must not be null.");
Assert.isNotBlank(value, "The value must be has text."); Assert.isNotBlank(value, "The value must be has text.");
Assert.isTrue(pattern.matcher(value).matches()); Assert.isTrue(RegexUtil.matches(value, pattern));
this.value = value; this.value = value;
} }