mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 15:13:55 +08:00
添加校验单参数是否是正确的手机号的方法
--ValidatorUtils.java 添加新方法
This commit is contained in:
@@ -2,6 +2,8 @@ package xiaozhi.common.validator;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
@@ -45,4 +47,23 @@ public class ValidatorUtils {
|
||||
throw new RenException(constraint.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号正则表达式
|
||||
*/
|
||||
private static final String PHONE_REGEX = "^1[3-9]\\d{9}$";
|
||||
|
||||
/**
|
||||
* 校验单参数是否是正确的手机号
|
||||
* @param phone 手机号
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isValidPhone(String phone) {
|
||||
if (phone == null || phone.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Pattern pattern = Pattern.compile(PHONE_REGEX);
|
||||
Matcher matcher = pattern.matcher(phone);
|
||||
return matcher.matches();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user