This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
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: 24195

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
It's not a secret anymore!