Skip to content

isValidDateString

The isValidDateString function checks if a string represents a valid date in a format accepted by JavaScript.

Syntax

typescript
isValidDateString(value: string): boolean;

Parameters

NameTypeDescription
strstringString to check

Returns

TypeDescription
booleanTrue if the string is a valid date string

Examples

typescript
isValidDateString("2024-06-10");
// => true

isValidDateString("10/06/2024");
// => true

isValidDateString("invalid date");
// => false

Notes

  • Useful for validating strings before converting them to dates.

References

Released under the MIT License.