Validation of dates

Results 1 to 2 of 2

Thread: Validation of dates

  1. #1
    Join Date
    Dec 1969

    Default Validation of dates

    Hi everybody!<BR>I am dealing with a problem while developping an application.<BR>In the application,people have to fill in a begin- and enddate a couple of times(Important:I can&#039;t use dropdown-lists for this,people must fill in the dates in regular input textfields).How can I control that the enddate isn&#039;t before the begindate?How can I control that people do not enter values above 31 for the day,and above 12 for the month?<BR>Can anyone help me???<BR><BR>Greetz!

  2. #2
    Join Date
    Dec 1969

    Default Convert it to a Date value...

    ...and then you can check the days and months. Once you know all the fields are valid dates, convert the being and end dates into Date values and compare them.<BR><BR>Something like:<BR><BR>var dtBegin = new Date(Date.parse(&#060;your begin date text field here&#062;));<BR>var dtEnd = new Date(Date.parse(&#060;your end date text field here&#062;));<BR><BR>if (dtBegin.getDay() ....<BR>if (dtBegin.getMonth() ....<BR><BR>if (dtBegin &#062; dtEnd)<BR> &#060;begin date is after end date&#062;<BR><BR>It&#039;s just rough code and you might have to use try/catch for invalid dates.<BR><BR>Have a look at for more information on the parse method and the Date object.<BR><BR>Oliver.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts