aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Allow only numbers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3102
    
  40

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 ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2183
    
    7
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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3102
    
  40

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://aspose.com/file-tools
 
subject: Allow only numbers?