aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Data validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Data validation" Watch "Data validation" New topic
Author

Data validation

Sam Stackly
Ranch Hand

Joined: May 04, 2002
Posts: 109
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

Joined: Feb 05, 2001
Posts: 17257
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Sam Stackly
Ranch Hand

Joined: May 04, 2002
Posts: 109
Thanks Mark,
It's great to have you around here,

Sam
 
 
subject: Data validation