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 ]
Joined: Aug 05, 2002
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.
Joined: Sep 29, 2000
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.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: Sep 08, 2001
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
Joined: Jul 05, 2002
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.