Javascript: check date in future in dd/mm/yyyy format? -
i'm trying check users input field see if in future , if in dd/mm/yyyy format have no idea why format part of code doesn't fire @ all! in fact nothing seems working on jsfiddle @ least "check date in future" function works locally.
i don't know correct way of going this.
to explain this, i've created fiddle
and full javascript code. need stay pure javascript way:
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 in past. please pick date.'); document.getelementbyid('error8').innerhtml = 'the date can\'t in past. please pick 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 please advise on issue?
thanks in advance.
one problem trying run senddate.match, senddate has been converted date object not have match method.
you should run regular expression before convert date, in validation, typically check input conforms format before run further validation range validation.
Comments
Post a Comment