date validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • onlymukti4u
    New Member
    • Mar 2007
    • 50

    date validation

    I need a validation for two date field where the date difference should not exceed 31 days,but the problem is in the date field the inputs are in the format of DDMMM like 22JUN, So If anyone knows this please send me the code or show me the way.

    Thanks
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Separate the date and month either by using substring or regular expressions.

    Once you have the month, you will need to convert it into an integer. Use an array of months and the index which matches is the number.

    Then, use the Date object methods to set the dates and compare using > or < (after adding 31 to the first date).

    Comment

    • onlymukti4u
      New Member
      • Mar 2007
      • 50

      #3
      How will I calculate if it will be a date of december last year and january this year.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by onlymukti4u
        How will I calculate if it will be a date of december last year and january this year.
        If you compare, JavaScript will do this for you. When you add 31 days to a date, it will automatically go to the next month/year.

        Comment

        Working...