mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-26 04:39:53 +01:00
添加校验单参数是否是正确的手机号的方法
--ValidatorUtils.java 添加新方法
This commit is contained in:
parent
0509ddb129
commit
aa251aa011
1 changed files with 21 additions and 0 deletions
|
|
@ -2,6 +2,8 @@ package xiaozhi.common.validator;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
|
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
|
@ -45,4 +47,23 @@ public class ValidatorUtils {
|
||||||
throw new RenException(constraint.getMessage());
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue