添加日期格式检查
This commit is contained in:
parent
c737798c29
commit
6792aea793
@ -47,6 +47,26 @@ public class RegexUtil {
|
||||
* 时间戳格式
|
||||
*/
|
||||
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]))*$");
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private static final Pattern PATTERN_YYYY_MM_DD = Pattern.compile("^(\\d{4})(0\\d{1}|1[0-2])(0\\d{1}|[1-2][0-9]|3[0-1])$");
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private static final Pattern PATTERN_YYYY_MM_DD_HH_MM_SS = Pattern.compile("^(\\d{4})(0\\d{1}|1[0-2])(0\\d{1}|[1-2][0-9]|3[0-1])([0-1][0-9]|(2[0-3]))([0-5][0-9])([0-5][0-9])$");
|
||||
/**
|
||||
* 时间戳(毫秒)
|
||||
*/
|
||||
private static final Pattern PATTERN_YYYY_MM_DD_HH_MM_SS_ZZZ = Pattern.compile("^(\\d{4})(0\\d{1}|1[0-2])(0\\d{1}|[1-2][0-9]|3[0-1])([0-1][0-9]|(2[0-3]))([0-5][0-9])([0-5][0-9])(\\d{3})$");
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private static final Pattern PATTERN_HH_MM_SS = Pattern.compile("^([0-1][0-9]|(2[0-3]))([0-5][0-9])([0-5][0-9])$");
|
||||
/**
|
||||
* 时间戳(毫秒)
|
||||
*/
|
||||
private static final Pattern PATTERN_HH_MM_SS_ZZZ = Pattern.compile("^([0-1][0-9]|(2[0-3]))([0-5][0-9])([0-5][0-9])(\\d{3})$");
|
||||
/**
|
||||
* 身份证
|
||||
*/
|
||||
@ -164,6 +184,56 @@ public class RegexUtil {
|
||||
return PATTERN_DATETIME.matcher(input).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间时间戳
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static boolean isYyyyMmDd(String input) {
|
||||
return PATTERN_YYYY_MM_DD.matcher(input).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间时间戳
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static boolean isYyyyMmDdHhMmSs(String input) {
|
||||
return PATTERN_YYYY_MM_DD_HH_MM_SS.matcher(input).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间时间戳
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static boolean isYyyyMmDdHhMmSsZzz(String input) {
|
||||
return PATTERN_YYYY_MM_DD_HH_MM_SS_ZZZ.matcher(input).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间时间戳
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static boolean isHhMmSs(String input) {
|
||||
return PATTERN_HH_MM_SS.matcher(input).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间时间戳
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static boolean isHhMmSsZzz(String input) {
|
||||
return PATTERN_HH_MM_SS_ZZZ.matcher(input).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断身份证
|
||||
*
|
||||
@ -241,4 +311,8 @@ public class RegexUtil {
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(isHhMmSs("1111111"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user