I am building a self-depreciating list of dates and am using Date.parse() to convert rich text into a timestamp. Right now, we have a system where the user enters the date themselves, and I use a token on the backend to pull it through to that specific page.
I am trying to 'protect the user' from entering a wrong date format.
Currently, if they enter January 12th, 2016 it won't be able to parse and create a timestamp due to th. However, if they enter January 12, 2016 it can create a timestamp.
Is there a way to replace these ordinal numbers on a dynamic string? I've tried a simple jquery find/replace, but have had no luck with getting it to remove the ordinal date texts.
What I've tried:
$('.my-button').each(function() {
console.log($(this).text());
var text = $(this).text().replace('st, ', '');
$(this).text(text);
});
Any ideas on a solution, or a way to make Date.parse(): accept these extra characters?