/**
     * 校验时间格式为2018-01-02
     * @param time
     * @return
     */
    public boolean validationTimeFormat(String time) {
        boolean bool = false;
        Pattern pattern = Pattern.compile("[0-9]*");
        if(time != null && time.length() == 10) {
            //校验前四位是否为数字
            if(pattern.matcher(time.substring(0, 4)).matches()) {
                //校验第五位是-
                if("-".indexOf(time.substring(4, 5))!=-1) {
                    //校验第6,7位是否为数字
                    if(pattern.matcher(time.substring(5,7)).matches()) {
                        //校验第8位是否为-
                        if("-".indexOf(time.substring(7, 8))!=-1) {
                            //校验第9,10位是否为数字
                            if(pattern.matcher(time.substring(8, 10)).matches()) {
                                bool = true;
                            }
                        }
                    }
                }
            }
            
        }
        return bool;
    }

注释:负数正则表达“^-?[0-9]+”,所有数字正则表达式“-?[0-9]+.?[0-9]+”

相关文章:

  • 2021-11-19
  • 2022-12-23
  • 2021-12-26
  • 2021-08-11
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-06
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案