In below Code i want to validate date between 02/08/2017 and 05/08/2017 and give us a alert which is Date is not in range
<script type="text/javascript"> function validate() { today = new Date(); fromdt= new Date("02/08/2017"); todate=new Date("05/08/2017"); if( document.myForm.entrydt.value == "" ) { alert( "Please Select Entry Date!" ); document.myForm.entrydt.focus() ; return false; } else if(!document.myForm.entrydt.value.match(letters3)) { alert("Entry Date: Enter Only Date Format i.e DD/MM/YYYY"); document.myForm.entrydt.focus() ; return false; } else if (!document.myForm.entrydt.value.today > startdt && !document.myForm.entrydt.value.today < todate) { alert("Entry Date: Enter Date in Proper Range"); document.myForm.entrydt.focus() ; return false; } return( true ); } </script> ==============================================================================
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" class="form-inline" role="form" name="myForm" id="myForm" onsubmit="return(validate());"> <div id="" class="container" > <div class="form-group"> <label for="entrydt">Entry Date</label>= <input class="form-control" style='font-weight:bold;text-transform:uppercase;' id="entrydt" type="text" name="entrydt" style='' placeholder="DD/MM/YYYY" value="" size="10"> </div> </div> </form>
Dateconstructor to see the accepted formats. Also remember thatDateactually includes both date and time, so you'll need to take that into accounting by for the end of your range.new Date("02/08/2017")will probably be parsed as 8 Feb 2017. It is not clear from your post wether it should be treated as that or 2 Aug 2017. See marked duplicates.