Solved

only entering numbers

Posted on 2002-03-19
8
164 Views
Last Modified: 2010-03-31
i'm asking the user to enter a number like entering his salary..how can i validate that the user it entering only a number.. to go on with the processes.. like if he enteres anything by mistake..an error message will appear.. but how to do the validation thing here..

waiting..
0
Comment
Question by:saroosh
8 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 50 total points
Comment Utility
something like

try {

   Integer.parseInt("12345");
   Float.parseFloat("12345.50");

} catch (NumberFormatException nfe) {
   // invalid string
}

0
 
LVL 4

Expert Comment

by:kylar
Comment Utility
If you're using Swing, create a document that doesn't allow the user to enter any non-digit characters and use a JTextField that utilizes your new document.

Kylar
0
 

Expert Comment

by:pv_raman
Comment Utility
If u are using TextField component,U can add a KeyListener to the text field.for each character verify whether that char is in between 0 and 9.
for eg, ch >=0 && ch <= 9, then only you allow user to enter, otherwise display error message to him.
or
create a document that doesnot allow the user to enter other than digits.Take the constructor of JTextField to utilize ur created document object.or use setDocument()

Hope this will help u.

Raman
0
 

Expert Comment

by:pv_raman
Comment Utility
If u are using TextField component,U can add a KeyListener to the text field.for each character verify whether that char is in between 0 and 9.
for eg, ch >=0 && ch <= 9, then only you allow user to enter, otherwise display error message to him.
or
create a document that doesnot allow the user to enter other than digits.Take the constructor of JTextField to utilize ur created document object.or use setDocument()

Hope this will help u.

Raman
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Expert Comment

by:dyma82
Comment Utility
bobbit31's is the most suitable solution!
0
 
LVL 1

Expert Comment

by:saurav17
Comment Utility

Hi saroosh,

Hope u could do that with isNan().


Regards,
K.J.S.
0
 
LVL 9

Expert Comment

by:Venci75
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: bobbit31
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
Per recommendation, force-accepted.

Netminder
EE Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now