File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes enter only numeric Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "enter only numeric" Watch "enter only numeric" New topic

enter only numeric

Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
Is there a way to add code that will only allow numbers to be entered in a field?
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

Can you give more detail on exactly what you need? when you said field,
did you meant TextField in a GUI(Swing/AWT/whatever)? or it also can be
a TextArea? or taking input from the Console?
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
It would be a TextField in a GUI that I only want to allow numbers to be entered. Basically it would be for entering a social security number.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

The Java Developer's Almanac online is a good source of examples; this one is very closely related to what you want to do.

[Jess in Action][AskingGoodQuestions]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

I use this, your welcome to use it also.

I agree. Here's the link:
subject: enter only numeric
jQuery in Action, 3rd edition