aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Allow only numbers? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Allow only numbers?" Watch "Allow only numbers?" New topic
Author

Allow only numbers?

Nebojsa Karan
Greenhorn

Joined: Oct 28, 2009
Posts: 2
I have one question.

How to allow only numbers to enter in text box and forbid letters and other non-numeric characters?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What kind of text box? Swing? If so, I'll move it to the appropriate forum. HTML? If so, I'll move it to another different appropriate forum. If HTML, are you using a framework? If so, I'll move it to possibly yet another different appropriate forum. Using JavaScript?
Nebojsa Karan
Greenhorn

Joined: Oct 28, 2009
Posts: 2
Swing
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2691
    
    3

Welcome to JavaRanch, Nebojsa

As far as I know there is no single method to do that.
You may do it by handling the user input - just have a look at this example.


Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 1788
    
    2
The above example is an old example.

Use either a JFormattedTextField or add a DocumentFilter to the Document.

More information about both options can be found in the Swing tutorial.
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2691
    
    3

Rob Camick wrote:Use either a JFormattedTextField or add a DocumentFilter to the Document.

Something I never used. Great
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Allow only numbers?
 
Similar Threads
TextField with comma
Need to insert 1.5 into a sql colunm on Number(2,2)
Obtaining the digits of a integer.
string validation
enter only numeric