This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help - with validating a TextField

 
khella smith
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have this code
and its works as it takes in a word from the text field and verifies it to see if it is a char
but i want it to take eg kelly smith at the same time so the space can also be verified is there a method for this ? that's for the text field to take only letters and space but not numbers i can't find any method or maybe did not know wat to look for in the api's can anyone help?
(edited by Cindy to put a meaningful Subject on this topic)
[ August 05, 2002: Message edited by: Cindy Glass ]
 
john guthrie
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you're using java 1.4 you should look at the regular expressions stuff in java.util.regex
my perl skills are a bit rusty, but a regexp a la (([A-Za-z]* ?)+) might get you in the ballpark.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you COULD put a KeyListener on the TextField and if the user enters a numeric value, just consume() it, or change it to some other character.
 
Erik Pragt
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really an answer to your question, but you could also create your own method, and validate against an char array which contains all valid characters.
Erik
 
Femi Alla
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Khella Smith,
I don't know if you are using AWT or Swing. Anyhow, with swing, this particular problem of yours gets easier the higher the version of JDK/SDK you are using.The InputVerifier class was introduced into Swing in JDK1.3 and could save one a lot of lines of code when validating a textfield. The APIs even have an example on it's usage, do check it out. Also JFormattedTextField was introduced in JDK1.4 and even has a more complete set of methods that support validating abitrary values in a JTextField.
It wouldn't be a bad idea for you to move up to a later version of the SDK (if you are using an old one, that is), moreso because it's................ free!.
Hope this helps.

Femi Alla.
SCJP2
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic