0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScriptで日付の判定をする

Last updated at Posted at 2020-02-18

実装

const hoge = new Date('aaa')
if(hoge.toString() === "Invalid Date"){
    console.log("日付エラー")
}

補足

new Date(1) ※1970/1/1扱いとか、new Date('2020/2/30') ※3/1扱い(2020年はうるう年)が許容されてしまうので微妙かも、、というかこれ単体だと微妙。。
少なくとも正規表現で日付のフォーマットになっているかくらいは別で見た方が良いですね。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?