-1

I have a regex validator but it only validates in the following format dd/mm/yyyy

export function validateDate(date: string) {
const regex = new RegExp('([0-2]{1}[0-9]{1}|3[0-1]{1})[/](0[1-9]|1[0-2])[/]([0-9]{4})');
return regex.test(date);
}

I would like to validate a date in the format

jsDate: Tue May 24 2022 10:08:18 GMT-0300 (Brasilia Standard Time)

I tried to look for some validators of this format, but I was not successful

i use mydatepicker angular date picker

Leonardo
  • 1
  • 3
  • You can create the date with `new Date("Tue May 24 2022 10:08:18 GMT-0300 (Brasilia Standard Time)")` (vanilla JS) then check if this date is valid or not with `== "Invalid Date"` for example (there's probably a better way than `==` to check this). Just found you can also use `Date.parse()` like [this](https://stackoverflow.com/questions/1353684/detecting-an-invalid-date-date-instance-in-javascript/1353710#1353710) – Marius ROBERT May 18 '22 at 13:27

0 Answers0