Results 1 to 4 of 4
  1. #1
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default Stop user entering letters in GUI, numbers only

    I am currently using exception handling to stop users entering letters in a GUI input. So I try to parse String to double and if this code fails I just assume the user has typed in letters or some other characters that cannot be parsed and then I catch and print a message telling them that only numbers are allowed.

    Java Code:
    x = Double.parseDouble(sx);
        y = Double.parseDouble(sy);
    Surely there must be a more elegant way to simply stop users trying to type in letters where only numbers are allowed.

    Thank you in advance for you help.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,770
    Blog Entries
    7
    Rep Power
    21

    Default

    Have a look at the JFormattedTextField class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  4. #4
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

Similar Threads

  1. Replies: 11
    Last Post: 01-14-2011, 07:36 PM
  2. converting letters to numbers
    By fenhoff in forum New To Java
    Replies: 2
    Last Post: 01-24-2010, 05:45 AM
  3. logic to restrict the user from entering the password morethan thrice?
    By kavitha_164951 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-12-2008, 03:18 PM
  4. How to stop entering Data
    By adeeb in forum AWT / Swing
    Replies: 1
    Last Post: 06-07-2008, 03:58 AM
  5. validating a string for numbers and letters?
    By lockmac in forum New To Java
    Replies: 1
    Last Post: 08-09-2007, 10:17 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
  •