0

I'm running in a really weird issue to me. I've created a function to validate if a string is a Date and if it's I convert it to a formated string Date

const date = new Date(text);
if (isValidDate(date) && !$.isNumeric(text) && typeof text != 'boolean' && text != null) {
    text = SweetMeSoft.getFormatedDate(date, 'yyyy-MM-dd', true)
}

The thing is when I receive a text that ends with a space and a number I'm receiving a valid date.

Date.parse('MICROFIBRE PVA VILEDA BLEUPQT 5')
result 988693200000

new Date('MICROFIBRE PVA VILEDA BLEUPQT 5')
Tue May 01 2001 00:00:00 GMT-0500 (Colombia Standard Time)

I understand that JS converts the string to dates using some heuristics algorithms and this king of things can happen, but how can I validate if a string is a real date?

Erick Velasco
  • 121
  • 5
  • 13

0 Answers0