When inputing string with number the new Date() is missbehaving, is there another way how to achieve this without regex?
let string = 'some string 1'; let invalid = new Date(string); it is still parsing as a Date value
Mon Jan 01 2001 00:00:00 GMT+0000 (Greenwich Mean Time) I'm expecting it as an invalid date
Update
let string = 'some string 1'; let invalid = new Date(string.replace(/\s/g, '')); Seem to resolve to Invalid Date as i want to and it seem to proper validate all dates also human readable dates like Sun, 1 Dec 2024 is handled correctly returning that it is a date indeed.
but still it have missbehaviour when entering
let string = 'some string, 0'; let invalid = new Date(string.replace(/\s/g, '')); console.log(invalid) Sat Jan 01 2000 00:00:00 GMT+0000 (Greenwich Mean Time)
Date.parsewhich only technically supports one format - anything else is up to the implementation to decide how to handle. In chrome at least, it appears to do as you've described. In Firefox, it returns an invalid date.10/12/2024American October or European December?) should discourage so. Require users to provide a fixed specific format and reject everything that doesn't match.