优化正则的使用。
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
package xyz.zhouxy.plusone.constant;
|
||||
|
||||
/**
|
||||
* 正则表达式常量
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
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");
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
Reference in New Issue
Block a user