Results 1 to 6 of 6
Thread: How to disallow letters?
- 02-16-2012, 07:42 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 49
- Rep Power
- 0
How to disallow letters?
Hi everyone I am trying to make an if statement but i'm not sure what terminology to use or if it exists.
What I am trying to do is this:
A user enters numbers in to an input field
The program then manipulates the numbers and sends out a different number.
What I want to do is so that if the user enters say "abc" instead of a number it will tell them to put in a number. For example
so that's the general idea. Not sure how to really go about this or if you can even do it. Any help is appreciated.Java Code:double input = Double.parseDouble(input.getText()); if (input == not a number) { output.setText("input a number); }Last edited by Reeling; 02-16-2012 at 07:50 PM.
- 02-16-2012, 08:35 PM #2
Re: How to disallow letters?
If input is a double, it can't have a getText() method.
I understand that you have some gaps in your knowledge, but please put effort into posting a reasonable sample of code for your question. Some other gems:What's an "input field"? It doesn't even tell us what GUI toolkit is involved: AWT/Swing/JFace/SWT/JavaFX/other.A user enters numbers in to an input field
Anyhow. If this is Swing, take a look at JFormattedTextField. And tell us which toolkit you're using, so that this can be moved to the appropriate forum.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-16-2012, 09:36 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 49
- Rep Power
- 0
Re: How to disallow letters?
actually input can be a double because i parsed the result to a double. Try not to insult me when you don't have the facts right.
Also the tool kit I am using is Swing, and by input field I mean just a regular text field. I looked at the formatted text field but couldn't see any options to restrict user input. I saw one field which was "input verifier" and thought they're might be something in there but it just came up saying "custom editing of this property is not supported."
Side note: There is no reason to be so hostile. If you have ideas or need more information I am glad to hear them or supply it. Please don't just arbitrarily insult me though.
Thanks
- 02-16-2012, 10:21 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
Re: How to disallow letters?
Side note: you where not insulted. You where given advice on how to ask a better question with all the information that we need to help sovle the problem.
Spend more time on the question and less on the "side note".
look at your posted code. You are tying to treat the same 'input" variable as a JTextField and a double.actually input can be a double because i parsed the result to a double.
Don't just randomly type code into a posting because you may make mistakes like that which doesn't help us. Post your Short, Self Contained, Correct Example which demonstrates the problem.
- 02-16-2012, 10:37 PM #5
Member
- Join Date
- Jan 2012
- Posts
- 49
- Rep Power
- 0
Re: How to disallow letters?
i see what you mean. it was just a miss communication on my part. Anyway, to me "please put some effort in to posting a reasonable example of code" seems like an insult. Also the way he words his other "suggestions" seem to be an insult.
Thanks for the advice camick. Next time I have a problem I'll remember those things. For now though I seem to have figured it out for my purposes using the "Character.isLetter()" method.
Thanks
- 02-17-2012, 12:26 AM #6
Re: How to disallow letters?
Either get a thicker skin or a tutor. If you're going to read insults into a request (yes, the word 'please' is in there) for better information on how to help you, you're never going to be able to make the best of a forum.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Key codes for the letters Å, Ä & Ö
By Alerhau in forum New To JavaReplies: 9Last Post: 09-13-2011, 09:10 PM -
How to allow specific letters only?
By ctmarco3 in forum New To JavaReplies: 7Last Post: 04-01-2011, 04:41 AM -
What does the letters mean?
By mustachMan in forum New To JavaReplies: 3Last Post: 02-11-2010, 09:50 PM -
disallow more than one login
By ajith_raj in forum New To JavaReplies: 4Last Post: 04-21-2009, 12:40 PM -
Disallow doPOST method in Sun Application server
By prakash_sahoo in forum Advanced JavaReplies: 5Last Post: 08-28-2008, 06:54 AM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks