Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript check if string is valid date using Date constructor

const isDate = (str) => {
  return (new Date(str) !== "Invalid Date") && !isNaN(new Date(str));
}

console.log(isDate('2020-01-01'))
console.log(isDate('abc'))
Source by thewebdev.info #
 
PREVIOUS NEXT
Tagged: #javascript #check #string #valid #date #Date #constructor
ADD COMMENT
Topic
Name
5+2 =