• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField that accept only integer input  RSS feed

 
Alicia Perry
Ranch Hand
Posts: 66
Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I have a GUI with a JTextField. I need to check that the input entered by the user is made up of only integers.
For example I accept: 1, 10, 530, ...
I do not accept: -10, 1.5, -6 ...

I would like to implement this control by using a regular expression so I would have a code like that.




The checkInteger(String input) method should check if the input string is correct or not.

How can I do to implement this control with regular expressions?
Is there an easier way to do it?

Thanks
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a pretty common question. Try Googling, "jtextfield restricted integer" and see if you find something you like. (You'll get over 200,000 pages to choose from )

Oh, hey! This is my 500th post in the Big Moose Saloon. Wow, am I ever glad I found this place.
 
Alicia Perry
Ranch Hand
Posts: 66
Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote:This is a pretty common question. Try Googling, "jtextfield restricted integer" and see if you find something you like. (You'll get over 200,000 pages to choose from )

Oh, hey! This is my 500th post in the Big Moose Saloon. Wow, am I ever glad I found this place.

I've solved, thanks!
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote: . . . my 500th post in the Big Moose Saloon. Wow, am I ever glad I found this place.
Congratulations.

And we sometimes succeed in being helpful
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!