• Post Reply Bookmark Topic Watch Topic
  • New Topic

Restricting Data Entry in TextFields

 
Damien O Sullivan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'd like to know is there a way to restrict a user from inputting certain characters into a TextField?

Is there something like isNumeric() available?

In Visual Basic, I was able to prevent the user entering certain characters of my choice into each textbox, however I've looked and I haven't been able to find a solution.
I've tried using the following else if as part of an if statement:

but it doesn't seem to work.

I'd appreciate any feedback I receive.

Thanks!
 
Campbell Ritchie
Marshal
Posts: 52513
118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damien O Sullivan wrote: . . . I'd like to know is there a way to restrict a user from inputting certain characters into a TextField?
Yes, there is


Is there something like isNumeric() available?
No, there isn't. When you push the bitton to process the data in your GUI you can have a regular expression evaluate your input. Or you can use a Scanner
In Visual Basic, I was able to prevent the user entering certain characters of my choice into each textbox, . . .
There is such a thing as a formatted text field, which probably does what you want.
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that JFormattedTextField is a Swing component, whereas you asked about TextField, which is an AWT component. However unless you have somebody forcing you to use AWT components, you should be using Swing anyway.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!