Is there a php function like checkdate () in JavaScript?

In php there is a checkdate function (month, day, year) that helps to check if the date matches the correct date or not. Is there a similar function in JavaScript or jQuery?

+3
source share
1 answer

You can easily create your own, but you should know how Javascript handles non-existent dates:

new Date(2010, 14, 34); // gives Sun Apr 03 2011, it just counts on.

So this would do the trick:

function checkDate(year, month, day){
  var d = new Date(year, month, day);

  return d.getFullYear() == year && 
         d.getMonth() == month &&
         d.getDate() == day;
}
+3
source

Source: https://habr.com/ru/post/1783665/


All Articles