jannasm1 Posted December 10, 2012 Share Posted December 10, 2012 i've a form user can enter any date , but i want to set a date range validation so the user can't add a date not in this range . for example: from 1-12-2012 to 1-1-2013 , so if user enter 2-1-2013 the system shouldn't accept it.. i've tried this javascript code but it doesn't work and doesn't give me any alert message even when date not in range .. can you help me with this ? or suggest other javascript code i can use instead this is part of my form : echo "<th> Date </th> <td> <input type='date' name='v2' value='' ></td>"; and this is the javascript code i've used <script language="javascript"> function validation(form) { var v2 = document.getElementById('v2'); var date = v2.value; if ( (v2 > new date('12/12/2012')) && (v2 < new date('1/1/2013')) ){ // date is in your valid range return true; } else { // date is not in your valid range alert("date is not in valid range") return false; } } </script> Quote Link to comment https://forums.phpfreaks.com/topic/271809-date-range-validation/ Share on other sites More sharing options...
codefossa Posted December 10, 2012 Share Posted December 10, 2012 What does the date come out as for the value of v2? (show it to me as a string) Quote Link to comment https://forums.phpfreaks.com/topic/271809-date-range-validation/#findComment-1398522 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.