Skip to content

isValidDateString

Checks whether a string can be parsed into a valid Date.

Uses the native Date constructor. Returns false for empty strings and any string that produces an Invalid Date.

Caveat: The native parser is lenient and implementation-dependent for non-ISO formats. For strict format validation, prefer a dedicated library or manual regex checks.

Available since v2.0.0

import { isValidDateString } from '@helpers4/date';
// or, from the all-in-one package (same code, one install):
import { isValidDateString } from 'helpers4/date';
isValidDateString(input: string): boolean
ParameterTypeDescription
inputstringThe string to validate

boolean — true if new Date(input) produces a valid date

isValidDateString('2025-01-19')            // => true
isValidDateString('2025-01-19T12:00:00Z')  // => true
isValidDateString('Jan 19, 2025')          // => true
isValidDateString('not a date')            // => false
isValidDateString('')                      // => false

View source on GitHub