• Post Reply Bookmark Topic Watch Topic
  • New Topic

SimpleDateFormat  RSS feed

 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im using a formatted text field with simple date format dd/mm/yyyy on my user interface

before executing a function i want to call a method which checks that the data in these text fields conforms with the format before proceeding.

how could i do this in code?

thanks
 
Oscar Gonzalez
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the Patern/Matcher clases and check it with a regex.
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also try the following:

 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I want to correct you that in SimpleDateFormatter 'MM' is different then 'mm'.

If you want to take the Month of the Year then you should use 'MM' or if you want to take the minutes of the hour.. then you should use 'mm'.



I hope everything is make clear to you now.
If any concern then revert back.
 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your replies, ill looking into this seriously this afternoon (playing with JTrees this morning!) if i get any problems ill let ya know!
 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems to work as far as major inconsistencys in the inputs goes but it does accept input in the form 00/00/00 AND 00/00/0000 would rather limit this to one date format if possible.
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then check the length of the string before trying the parse
(i.e. yourTextInput.length( ) == 10)
 
Deyna Cegielski
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup, that fixed it, cheers!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!