File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes help wanted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help wanted" Watch "help wanted" New topic
Author

help wanted

david hu
Ranch Hand

Joined: Jul 20, 2001
Posts: 143
How to check whether the string entered in the text field is consisted of only digit letters
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
you can maybe try to convert it to a number and if no NumberFormatException is thrown then there are only digits.

Another method is to check if every character of the String is a digit or not

HIH

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi david,
it's easy.. just implement KeyListener on the text field and on each ket stroke check the "keyChar" property of the KeyEvent using getKeyChar() method. check it is between 0-9 and you are done.
regards,
maulin.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help wanted