Depending on where you are getting your date info from, i.e. web page,
server generated, you have a couple of options.
1) use javascript to check it on your form. There are a ton of examples out
there.
2) Check the format in your servlet. For example you could generate your own
SimpleDateFormat and compare it to the one that was entered to see if it is
the correct format. Your dates can be string objects so this would be easy
to do. Checking for seperators could easily checked for, for example,
if ((startDate.charAt(2) == '/') && (startDate.charAt(5) == '/') &&
(startDate.length() == 8)){
// do something
}
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of João
Robertson Kramer Santana
Sent: Friday, February 09, 2001 10:57 AM
To: [EMAIL PROTECTED]
Subject: Date Validation
Hi people,
I know that this is not a servlet especific question, but we
forwarded this to some list and got no answer.
We work with the date in the following format : DD/MM/YYYY.
The problem is that we area using the function bellow to convert a
string to date and having strange results:
public static java.sql.Date stringToSqlDate (String inData) {
SimpleDateFormat formatador = new
SimpleDateFormat("dd/MM/yyyy");
ParsePosition marcador = new ParsePosition(0);
java.util.Date auxData;
auxData = formatador.parse(inData,marcador);
java.sql.Date outData;
outData = new java.sql.Date(auxData.getYear(),
auxData.getMonth(), auxData.getDate());
return outData;
}
INPUT OUTPUT
------- -------
32/01/2001 01/02/2001
31/13/2001 31/01/2001
62/07/2001 31/08/2001
As you can see the function shifts the days or months if they area
invalid. I just would like to have a function to test if my date is correct
and have no shifting.
Can someone help us .
bye
jk
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html