• 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

Date Validation (Month and Day)

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello guys!

How would I check my date input so that it will validate
the maximum days per month.
For example:
Jan, Mar, May, Aug, Oct, Dec (31 days)
April, June,Sept, Nov (30 days)...

Please share me your ideas..

Addtional: Separate field name for month and day.

Thank you

Hiro

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
If you intend to use javascript,this can be easily done by putting if else condition.Please note that you will require year field also to validate for February.

Apple Man
 
Hiroyuki Suzuki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for your reply, but if I used javascript, I will not be using alert message for the error message instead I should use the html:error..
Will it be possible?

Hiro
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd suggest doing server-side validation in the validate() method of your ActionForm. I'd use the parse method of the SimpleDateFormat class. This class will simply throw a ParseException if the date is invalid. If it does, catch it and format an ActionError instance. Since the Java base classes handle all the details of date validation, why re-invent the wheel?

Oh, and one other thing: Make sure you call setLenient(false) on the SimpleDateFormat instance.
[ September 04, 2007: Message edited by: Merrill Higginson ]
 
Shane W
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Merill's suggestion is good,only problem being the call to the server.Incase you don't mind that,you can use it. Also,not sure if we can use html:error incase of Java script.
Apple Man
 
Hiroyuki Suzuki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for your replies..
Ive already solved this..

In my form I added another field (maxDay1 and maxDay2)
that will return OK and NG, i used this field in my validation.xml using validwhen, when the field
is equal to OK, then it is valid, if it is NG, it is invalid..

This is my code, it also checks number of days in february when it is leap year or not.
 
Hiroyuki Suzuki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem now is how to validate the entered dates so that it will check if the "viewEndDate" is higher than the "viewStartDate"..

-Hiro-
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic