10 examples of 'javascript check if string is date' in JavaScript

Every line of 'javascript check if string is date' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
321function isDateString(value) {
322 return value && (typeof value == 'string' || value.hasOwnProperty('start') && typeof value.start == 'string');
323}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

660function is_date(str){
661 var objRegExp = /^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/;
662 return objRegExp.test(str);
663}
4function isDate(date) {
5 return (
6 !!date &&
7 typeof date === 'object' &&
8 Object.prototype.toString.call(date) === '[object Date]'
9 );
10}
49function isDate(value) {
50 return /\d{2,4}-\d{2}-\d{2}[T -_]\d{2}:\d{2}:\d{2}/.test(value);
51}
35function isDate(value) {
36 return (value && typeof value == 'object' && toString.call(value) == dateClass) || false;
37}
50function isDate(d) {
51 return isObject(d) && objectToString(d) === '[object Date]'
52}
24export function isDate(value) {
25 return typeOf(value) === 'date' && !isNaN(value.getTime());
26}
93export function isDate(value) {
94 return checkPrototype(value, 'Date');
95}
328function isDate(d) {
329 return typeof d === 'object' && objectToString(d) === '[object Date]';
330}
87function isDateValid(value) {
88 const matched = value.match(dateRe);
89
90 if (matched) {
91 const epoch = Date.parse(value);
92 if (!epoch && epoch !== 0) return false;
93
94 const d = new Date(epoch);
95 d.setTime(d.getTime() + d.getTimezoneOffset() * 60 * 1000);
96
97 if (
98 d.getFullYear() == matched[1] &&
99 d.getMonth() + 1 == +matched[2] &&
100 d.getDate() == +matched[3]
101 ) {
102 return true;
103 }
104 }
105
106 return false;
107}

Related snippets