java正则表达式

我们两清 提交于 2020-03-22 17:11:56

这是一个检测时间格式是否正确的方法,例如2020-03-22

 1 public static boolean isValidateRunningDate(String input) {
 2         //正则匹配
 3         Matcher matcher = null;
 4         boolean result = false;
 5         String regex = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
 6         if (input != null && !input.isEmpty()) {
 7             Pattern pattern = Pattern.compile(regex);
 8             matcher = pattern.matcher(input);
 9         }
10         if (matcher != null) {
11             result = matcher.matches();
12         }
13         return result;
14     }

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!