aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes startdate,endDate validations how is it done? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "startdate,endDate validations how is it done?" Watch "startdate,endDate validations how is it done?" New topic
Author

startdate,endDate validations how is it done?

Liz Brown
Ranch Hand

Joined: Oct 22, 2002
Posts: 112
HI,
I have 2 date fields on form. StartDate(fromDate) and EndDate(toDate). Currently I have a calender image which is linked with javascript to click on date and it comes/populates on the text field. User cannot add the date directly in the text field.

But now the user should also be allowed to put the dates with hand type in these 2 fields and also could use the calender if they want to use (they can click on it and the date populates).
what is generally done in this case? The required format is mm/dd/yyyy format. But the user could also enter dd/mm/yyyy format. It the date is likely to be understood like 12/25/2005 it's ok. But if user enters by mistake dd/mm/yyyy like 25/12/2005 then it's an error. How is the format checked? How is it validated?

Is it checked with javascript at client side or checked in backend side in java application?
[ May 26, 2005: Message edited by: Bear Bibeault ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Clientside validation with JavaScript is fallable and shouldn't be relied on. Always validate serverside.

To control the format of your dates why not change from two input fields to six - day, month and year for each of the two dates? That way rather than trying to anticipate how many combinations of possible date formats the user could enter you tell them which format your application requires.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Paul Sturrock:
Clientside validation with JavaScript is fallable and shouldn't be relied on. Always validate serverside.

To control the format of your dates why not change from two input fields to six - day, month and year for each of the two dates? That way rather than trying to anticipate how many combinations of possible date formats the user could enter you tell them which format your application requires.


Or better, 3 select lists for each date.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Liz Brown
Ranch Hand

Joined: Oct 22, 2002
Posts: 112
thanks for your suggestions. Do you know a sample code which already exists online?
Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

The problem is going to be populating the date fields using the calendar. I don't know whether you're using a third-party component or not but there should be a way to capture and parse the return value from the calendar picker to populate the three separate fields rather than the single field.


SCJP, SCWCD
Liz Brown
Ranch Hand

Joined: Oct 22, 2002
Posts: 112
we are supposed to use Javascript.
Does javascript automatically detect the format of Date?
If yes, any suggestions on how to check it?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56229
    
  13

Moved to the HTML/Javascript forum.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
JavaScript will use the format of "MM/DD/YYYY"

but how would you tell the difference bewteen

04/05/2005

are we talking April 5th or May 4th?

basically you need to state the date format on your form.

Eric
Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

So assuming your calendar picker returns a JavaScript date, just parse the date into the three values you need.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: startdate,endDate validations how is it done?
 
Similar Threads
SimpleDateFormat
Bringing up a calender
Updation of date column
Date validation in struts....
calcuate days in a calender.era or between two days