Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check if a date time string is a valid date in js

const isValidDate = function(date) {
    return (new Date(date) !== "Invalid Date") && !isNaN(new Date(date));
}
Comment

js validate date object

function isValidDate(dateObject){
    return new Date(dateObject).toString() !== 'Invalid Date';
}
Comment

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'))
Comment

javascript validate date

var date_regex = /^(0[1-9]|1[0-2])/(0[1-9]|1d|2d|3[01])/(19|20)d{2}$/;
if (!(date_regex.test(testDate))) {
    return false;
}
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 :: get random id javascript 
Javascript :: copy Konva Transform object 
Javascript :: firebase iterate object 
Javascript :: why is necessary to run react-native run 
Javascript :: how to only register one click on nested component and not parent component in react js 
Javascript :: Script test to be oneOf 
Javascript :: vscode php format brackets 
Javascript :: how to disable search box and placeholder by putting some conditions using js 
Javascript :: js get current top position event listeners 
Javascript :: js convert charcode to char 
Javascript :: non-arrow functions are forbidden $(document).ready(function() { 
Javascript :: load json object from file frontend javascript 
Javascript :: ngreadonly 
Javascript :: ameca face expression code xcode 
Javascript :: find component inside tree with enzyme shallow wrapper 
Javascript :: how to signup users without login in firebase js 
Javascript :: isPalindrome 
Javascript :: js get each pair of values from an array 
Javascript :: python faker json 
Javascript :: express.js 
Javascript :: Checking if the first letter of the string is uppercase 
Javascript :: react clikc with ref 
Javascript :: js particles without plugin 
Javascript :: bootstrap dropdown with state 
Javascript :: when i add data into the input it disappeared in react 
Javascript :: SH1 in react native 
Javascript :: jquery ajax snippet 
Javascript :: odoo js reload widget 
Javascript :: html document from string javascript 
Javascript :: Example Of _.extend 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =