This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data validation

 
Sam Stackly
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys
What is the best way for data validation of numeric input ?
1- in keypressed event
2- after posting data, in controller
Thanks
Sam
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way to validate data in a JTextField is to us a PlainDocument, this can be used to prevent certain characters from being entered and also the length. Look at the API at the PlainDocument class, and extend it and you can create a NumericDocument, then extend the JTextField and create a NumericTextField.
Or check isDigit when you do #2. I think #2 is better because it won't fire as much as #1 will.

Mark
 
Sam Stackly
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark,
It's great to have you around here,

Sam
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic