I have been searching a lot to find out how can I know whether the date has overflown. Basically I want to identify invalid date strings. for Example using normal javascript date class or moment when we provide a date string like "4/31/2021" it overflows because April doesn't contain 31st date. so it jumps to next date valid date that is "5/1/2021".
moment has this strict validation like
moment("4/31/2021","MM/DD/YYYY",true).isValid() //false
where it provides strict validation for such overflown dates. but since in my use Case user can enter whatever the date string he wants and in different formats. I want to validate the date string. so the only way for me is to iterate over all the known formats and check with true
flag but then sometimes user can also enter time component with it which makes it even worse then we need to iterate through all the datetime formats as well.
is there any better/optimized way to handle this?