Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

is it normal behaviour of SImpleDateFormat?

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code.

Now if i creat SimpleDateFormat with the string MM/dd/yy the behaviour of JtextField is normal.
By normal i mean it accepts date as 11/11/11 only and not 11/11/11111111
But if i create SimpleDateFormate with String MM/dd/yyyy
the formattted textfield can accept year upto 9 digit.
i mean i can enter date as
02/03/12345678
Howver i was expecting that user can only enter
02/03/1234 [after validation]
but he can enter value
02/03/12345678
??
any idea??
the validation for MM/dd/yy is working fine.
here is the test code

[ July 23, 2003: Message edited by: aminur rashid ]
 
Bartender
Posts: 1843
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is normal behaviour for the SimpleDateFormat. Anytime you have four characters together, it will accept (as literal), the value entered. Thus:
MM/dd/yyyy
will accept:
03/10/1980 - 10 March 1980 CE
04/01/34908 - April Fool's Day, 34908 CE
11/11/11 - 11 November, 11 CE (When Caesar Augustus was emperor of Rome)
If you want to limit the number of digits in the year, you will have to implement some other validation routine.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to work just fine to me. The world doesn't come to an end in 9999 (If it does, we'll never see it)
If you wish to restrict the users input closer, you'll need to write your own method.
 
aminur rashid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Carl Trusiak End is near.....
.....
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic