Results 1 to 6 of 6
Like Tree3Likes
  • 1 Post By DarrylBurke
  • 2 Post By camickr

Thread: How to disallow letters?

  1. #1
    Reeling is offline Member
    Join Date
    Jan 2012
    Posts
    49
    Rep Power
    0

    Default 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

    Java Code:
    double input = Double.parseDouble(input.getText());
    
    if (input == not a number)
    {
    output.setText("input a number);
    }
    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.
    Last edited by Reeling; 02-16-2012 at 08:50 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default Re: How to disallow letters?

    Quote Originally Posted by Reeling View Post
    Java Code:
    double input = Double.parseDouble(input.getText());
    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:
    A user enters numbers in to an input field
    What's an "input field"? It doesn't even tell us what GUI toolkit is involved: AWT/Swing/JFace/SWT/JavaFX/other.

    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.

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Reeling is offline Member
    Join Date
    Jan 2012
    Posts
    49
    Rep Power
    0

    Default 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

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default 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".

    actually input can be a double because i parsed the result to a double.
    look at your posted code. You are tying to treat the same 'input" variable as a JTextField and 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.
    Fubarable and DarrylBurke like this.

  5. #5
    Reeling is offline Member
    Join Date
    Jan 2012
    Posts
    49
    Rep Power
    0

    Default 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

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default 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.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Key codes for the letters , &
    By Alerhau in forum New To Java
    Replies: 9
    Last Post: 09-13-2011, 10:10 PM
  2. How to allow specific letters only?
    By ctmarco3 in forum New To Java
    Replies: 7
    Last Post: 04-01-2011, 05:41 AM
  3. What does the letters mean?
    By mustachMan in forum New To Java
    Replies: 3
    Last Post: 02-11-2010, 10:50 PM
  4. disallow more than one login
    By ajith_raj in forum New To Java
    Replies: 4
    Last Post: 04-21-2009, 01:40 PM
  5. Disallow doPOST method in Sun Application server
    By prakash_sahoo in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2008, 07:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •