Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check if string is valid date

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

console.log(isDate('2020-01-01'))
console.log(isDate('abc'))
Comment

check if the Date is valid

const isDateValid = (...val) => !Number.isNaN(new Date(...val).valueOf());

isDateValid('December 17, 1995 03:24:00'); // true
isDateValid('1995-12-17T03:24:00'); // true
isDateValid('1995-12-17 T03:24:00'); // false
isDateValid('Duck'); // false
isDateValid(1995, 11, 17); // true
isDateValid(1995, 11, 17, 'Duck'); // false
isDateValid({}); // false
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery page finished loading 
Javascript :: ExpressionChangedAfterItHasBeenCheckedError: 
Javascript :: angular timestamp 
Javascript :: how to copy text in the clipboard in js 
Javascript :: match word in string js 
Javascript :: javascript get file extension from string 
Javascript :: check if array does not contain value javascript 
Javascript :: import jsx file without extension 
Javascript :: declaration vue 3 variables 
Javascript :: javascript get text between two strings 
Javascript :: checkbox on click jquery 
Javascript :: Jquery search in json 
Javascript :: javascript explode 
Javascript :: p5.js create button 
Javascript :: jquery checkbox checked or not 
Javascript :: loop through object js 
Javascript :: remove everything except alphabet and number js 
Javascript :: javascript last index 
Javascript :: convert csv to json powershell code 
Javascript :: javascript zero pad 
Javascript :: add all elements in array javascript 
Javascript :: javascript loop through array of objects 
Javascript :: javascript fill array 
Javascript :: reset form function javascript 
Javascript :: useHistory react-router-dom 
Javascript :: remove element from array in an immutable way 
Javascript :: javascript create a function that counts the number of syllables a word has. each syllable is separated with a dash -. 
Javascript :: file extension regex javascript 
Javascript :: nested array of object shows as object in console log output js 
Javascript :: exit extension from chrome javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =