Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JTextField Validation

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. I want to make one JTextField that only allows numeric input.
2. I want to make one JTextField that only allows a-z, 0-9 and
underscore(_) with the first charecter must be a-z.
Please help as soon as possible with example.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way would be to override the processKeyEvent method of your components. That way you can intercept an typed in characters and check to see if the user typed in a valid character. If the character is invalid, disallow the character and notify the user by any means neccessary. If the character is valid, allow the character by simply calling the super class' processKeyEventMethod.
To ensure the processKeyEvent method is called you may have to explicitly state your components want to process these events. To do this call enableEvents(java.awt.AWTEvent.KEY_EVENT_MASK) on your components.

------------------
Brent Worden
http://www.Brent.Worden.org/
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kaustuv,
Still if u require answer for 1 u can see the following link.
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#validtext
Venkat


Originally posted by Kaustuv Bhattacharya:
1. I want to make one JTextField that only allows numeric input.
2. I want to make one JTextField that only allows a-z, 0-9 and
underscore(_) with the first charecter must be a-z.
Please help as soon as possible with example.


reply
    Bookmark Topic Watch Topic
  • New Topic