新增用户名格式校验
This commit is contained in:
parent
ab41103a24
commit
8632d9a075
@ -51,6 +51,10 @@ public class RegexUtil {
|
||||
* 身份证
|
||||
*/
|
||||
private static final Pattern PATTERN_IDENTITY = Pattern.compile("(^\\d{15}$)|(^\\d{17}(x|X|\\d)$)");
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private static final Pattern PATTERN_USERNAME = Pattern.compile("^[a-zA-Z0-9_\\s]+$");
|
||||
/**
|
||||
* 字母
|
||||
*/
|
||||
@ -166,6 +170,16 @@ public class RegexUtil {
|
||||
return PATTERN_IDENTITY.matcher(input).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户名
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static boolean isUsername(String input) {
|
||||
return PATTERN_USERNAME.matcher(input).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是字母
|
||||
*
|
||||
|
@ -136,7 +136,12 @@ public class AnnotationUtil {
|
||||
if (StringUtils.isBlank(verifyType)) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.equals("phone", verifyType)) {
|
||||
if (StringUtils.equals("username", verifyType)) {
|
||||
if (!RegexUtil.isUsername(value)) {
|
||||
throw new ParamsException(String.format("%s格式只能是字母、数字和下划线", name));
|
||||
}
|
||||
return;
|
||||
} else if (StringUtils.equals("phone", verifyType)) {
|
||||
if (!RegexUtil.isPhone(value)) {
|
||||
throw new ParamsException(String.format("%s格式非手机格式", name));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user