Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help wanted

 
david hu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to check whether the string entered in the text field is consisted of only digit letters
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can maybe try to convert it to a number and if no NumberFormatException is thrown then there are only digits.

Another method is to check if every character of the String is a digit or not

HIH

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi david,
it's easy.. just implement KeyListener on the text field and on each ket stroke check the "keyChar" property of the KeyEvent using getKeyChar() method. check it is between 0-9 and you are done.
regards,
maulin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic