I'm having trouble verifying the user input field to check if it is in the future and follows the dd/mm/yyyy format. The code I've written doesn't seem to execute the format validation part, and for some reason, nothing is working on Jsfiddle. However, the "check date in the future" function does work when tested locally.
I'm unsure about the correct approach to tackle this issue.
To illustrate, I've set up a demo on FIDDLE
Below is my complete javascript code. I prefer sticking with pure javascript:
function checkdate(){
//var sendDate = document.getElementById('send_year').value + '/' + document.getElementById('send_month').value + '/' + document.getElementById('send_day').value;
var sendDate = document.getElementById('returning_date').value;
sendDate = new Date(Date.parse(sendDate.replace(/-/g,' ')))
today = new Date();
today.setHours(0,0,0,0)
if (sendDate < today) {
//alert('The date can\'t be in the past. Please pick another date.');
document.getElementById('error8').innerHTML = 'The date can\'t be in the past. Please pick another date.';
return false;
} else {
document.getElementById('error8').innerHTML = '';
}
if(sendDate.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/)) {
alert('works out');
}
}
Could someone offer guidance on this problem?
Thank you in advance.