|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Date Validation by Javascript
I have two fields in a forom which are start date and end date, I want to check the end date cannot be early than the start date, I able to do it by using the code below but when I select single digit day and two digit day, it cannot compare, such as 5 and 20, even though 20 is later than 5 but it still prompt error.
Can javascript compare single digit and two digits or not? function validateForm() { if (bookingform.endtime.value<=bookingform.starttime.value) { alert('Your End Hour must later than the start hour.') bookingform.endtime.focus() return false } if( (bookingform.rep_type[1].checked) || (bookingform.rep_type[2].checked) ) { if((bookingform.rep_end_year.value==bookingform.ye ar.value) && (bookingform.rep_end_month.value==bookingform.mont h.value)) { if(bookingform.rep_end_day.value<=bookingform.day.value) { alert("Your repeat end day must later than the start day") bookingform.rep_end_day.focus() return false } } if ((bookingform.rep_end_year.value==bookingform.year .value) && (bookingform.rep_end_month.value<bookingform.month.value)) { alert('Your Repeat End Month must later than the Start Month') bookingform.rep_end_month.focus() return false } if(bookingform.rep_end_year.value<bookingform.year.value) { if(bookingform.rep_end_month>bookingform.month.value) { alert("Your repeat end year must later than the start year") bookingform.rep_end_year.focus() return false } } var aa=((bookingform.rep_end_year.value)-(bookingform.year.value)); if(aa>=2) { alert("Hello world") return false } } return true; } |
|
#2
|
|||
|
|||
|
RE: Date Validation by Javascript
Why dont you try out writing your own function for converting your dates to timestamps.. It will be easy for comparison then.. Not a high end one.. Just a basic one
Somthing like TmStamp=Day+Month+Year |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Date Validation by Javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|