Date Validation

Discussion in 'JavaScript' started by adamjblakey, Jan 16, 2008.

  1. #1
    Hi,

    I am trying to validate 2 date fields one which is the from date and the other which is a to date.

    I need to add validation to check that is the return date is greater than the start date then tell the user.

    I have done this and thought it was working but say i put 28/01/2008 for the first field and put 02/02/2008 for the second it tells the user that the return date is greater than the start date. It seems that it must only be taking the first number and not taking into consideration the date.

    Here is the code:
     
    function checkform ( form )
    {
      
      if (form.arrivaldate.value > form.returndate.value) {
        alert( "Please enter a return date greater than your arrival date." );
        form.returndate.focus();
        return false ;
      }
      
      
      // ** END **
      return true ;
    }
    Code (markup):
    Any ideas?
    Cheers,
    Adam
     
    adamjblakey, Jan 16, 2008 IP
  2. jwlnewsome

    jwlnewsome Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    jwlnewsome, Jan 16, 2008 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    So do you mean i need to change the input to something like 2008.03.14 in place of 28/01/2008.

    If i did this what would i change the validation JavaScript to?
     
    adamjblakey, Jan 17, 2008 IP