• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checking Date

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
i want to check the date, f.e. 1979.12.12 which is written from a user in to a grafical window.
It must be in this order yyyy.mm.dd because it's met to be written in a jdbc (mysql) database.
How can i check that the date is written right (numbers, not letters and in right oder)?
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is ur name Really RED RED
Anyway provide a calendar. U dont have to worry about the way a user enters.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another possibility is using a Format (SimpleDateFormat should work for you) and create a JFormattedTextField with it.

You can also use the Format itself to check your date:
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(Let's help the moderators a bit...)

Hi,

Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Joke names and "handles" aren't acceptable. You'll find that many Ranchers won't be interested in helping you until you follow this rule.

You can change your display name
here. Thanks for your cooperation.
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recomend to use:

setLenient(false);

just after creating the simpledateformat. This option checks that the string precisely match this object's format
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you choose to provide a calendar, you can find some here http://mattkruse.com/javascript/calendarpopup/

then you could make the date into any format you wish.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Praveen, that site lists JavaScript calendars, not Java.


I've written a DateChooser class once, similar to javax.swing.ColorChooser (you need JGoodies Forms for the layout - feel free to edit if you don't want the library):
Alternatively, but this does not work with all formats (unfortunately yyyy.MM.dd is not supported), you can use a JSpinner for it:If you double click on the year, month or date part of this spinner you can use the spinner's buttons to change only that part.
With yyyy.MM.dd it can only change the year.

[ November 16, 2005: Message edited by: Rob Spoor ]
[ November 16, 2005: Message edited by: Rob Spoor ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic