新增时间戳正则判断

This commit is contained in:
wenc000 2020-04-20 23:18:47 +08:00
parent 288fdc5c61
commit 4477561d92
2 changed files with 19 additions and 0 deletions

View File

@ -43,6 +43,10 @@ public class RegexUtil {
* 日期格式
*/
private static final Pattern PATTERN_DATE = Pattern.compile("^(\\d{4})[-\\/](\\d{1}|0\\d{1}|1[0-2])([-\\/](\\d{1}|0\\d{1}|[1-2][0-9]|3[0-1]))*$");
/**
* 时间戳格式
*/
private static final Pattern PATTERN_DATETIME = Pattern.compile("^(\\d{4})[-\\/](\\d{1}|0\\d{1}|1[0-2])([-\\/](\\d{1}|0\\d{1}|[1-2][0-9]|3[0-1]))*(\\s+)([0-1][0-9]|(2[0-3])):([0-5][0-9])(:([0-5][0-9]))*$");
/**
* 身份证
*/
@ -142,6 +146,16 @@ public class RegexUtil {
return PATTERN_DATE.matcher(input).matches();
}
/**
* 判断时间戳
*
* @param input
* @return
*/
public static boolean isDatetime(String input) {
return PATTERN_DATETIME.matcher(input).matches();
}
/**
* 判断身份证
*

View File

@ -161,6 +161,11 @@ public class AnnotationUtil {
throw new ParamsException(String.format("%s格式非日期格式", name));
}
return;
} else if (StringUtils.equals("datetime", verifyType)) {
if (!RegexUtil.isDatetime(value)) {
throw new ParamsException(String.format("%s格式非时间戳格式", name));
}
return;
} else if (StringUtils.equals("identity", verifyType)) {
if (!RegexUtil.isIdentity(value)) {
throw new ParamsException(String.format("%s格式非身份证格式", name));