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 Restricting numeric input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Restricting numeric input" Watch "Restricting numeric input" New topic

Restricting numeric input

Timea Darryl

Joined: Sep 13, 2005
Posts: 3
I am new to Java, and I am trying to make 3 text fields; but I want the input in each of those text fields restricted to 1 digit(between 0-9). How can I do this?javascript: x()
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

OK, is this a Swing Textfield or an HTML one?


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Timea Darryl

Joined: Sep 13, 2005
Posts: 3
It is a Swing JTextField
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> It is a Swing JTextField

you could set your own document for the textfield,
but a simpler solution might be to use a JSpinner

Timea Darryl

Joined: Sep 13, 2005
Posts: 3
Wow! Thanks, Michael, that is amazing. I compiled it and ran it, and it looks awesome, although I do not understand how it works. I understand the spinner, in fact I wanted to use the Choice()class, but I am restricted to JTextField or JFormattedTextField, and everything I found on the net about restricting input to the JTextField was too confusing. So now I am going to try to figure out what you did with that number limiter class. Thanks again.
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Hey Michael, It was simple as i always wanted

it was not my problem , but i used this code...


Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
In java script u have to use the ascii value in between 48- 57
so on the basis of that u can do that

Warm Regards<br />vikassheelgupta<br />9911005168
I agree. Here's the link:
subject: Restricting numeric input
It's not a secret anymore!