---
title: "JS日期格式校验/判断"
author: "hq82001"
date: "2020-02-29T21:56:40Z"
tags: []
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2020-02-29T21:56:40Z"
id: 2512705
url: "https://hq82001.iteye.com/blog/2512705"
---

function checkDate(dateStr){

            var a = /^(\\d{4})-(\\d{2})-(\\d{2})$/

            if (!a.test(dateStr)) {

                return false

            }else{

                return true;

            }

        }

直接调用方法：

 

            if(!checkDate("2019-05-29")){

                alert("格式不正确!");

            }else{

                alert("格式正确!");

            }

 

原文链接：https://blog.csdn.net/pk694046220/article/details/90671217