0

I have tried Date.parse(), Date() and many other solution but no proper solution yet without checking it's pattern using regex(or external package like moment.js) first.

Attaching screenshot of sample which should be invalid date

e.g. Test - 7

enter image description here

jignesh
  • 1,336
  • 1
  • 11
  • 24
  • Does this help? https://stackoverflow.com/a/1353711/2472398 – gru Jan 17 '22 at 14:19
  • 1
    There's no reliable way to use the native Date API for this. You'll need to use a 3rd-party library, such as date-fns https://date-fns.org/v2.28.0/docs/isValid – Will Jenkins Jan 17 '22 at 14:22
  • What formats do you consider to be valid? E.g. "christmas 2015" is a legitimate date, but probably not one that you consider valid – byxor Jan 17 '22 at 14:22
  • @byxor Formats pattern used over here - https://www.w3schools.com/js/js_date_formats.asp – jignesh Jan 17 '22 at 14:27
  • @byxor I have tested "christmas 2015" and it's not actually converted to valid acceptable date e.g. 25 Dec 2015 – jignesh Jan 17 '22 at 14:28
  • @AlexGru I have tried now, it's not working as our date is a string object not date one. – jignesh Jan 17 '22 at 14:29
  • @WillJenkins let me try this.. – jignesh Jan 17 '22 at 14:30
  • @WillJenkins from my understanding it's formatting utility - I think it does not help to validate date in this case. – jignesh Jan 17 '22 at 14:33

0 Answers0