Hello all! I'm having a problem here... I would like to have all non alpha characters "stripped" and not accepted from a username input field... As an example you can see:
In this example the quote character is disallowed. What I would like to do is have all non alpha characters disallowed.. I've tried And
To no avail... any pointers??? Thanks in advance Slim
Larry Helmerich
Greenhorn
Joined: Aug 29, 2001
Posts: 1
posted
0
Remember that Java uses the Unicode character set so testing for "alpha" characters gives you more than just A-Za-z. You can use static methods in java.lang.Character to test a Character. For example, public static boolean isLetterOrDigit(char ch) method will return true if ch is either a letter or a digit. But, I don't think that the code you have is what you want to do. Instead of "stripping" off the characters that are unacceptable your input field should prevent the user from ever typing them in the first place. If you are using the AWT TextField class this is a pain to do, but if you are using the Swing JTextField then it is not that difficult. The key to doing this is to create a new javax.swing.text.Document Object that doesn't allow the illegal characters and then call the JTextField's setDocument method passing it the new Document Object. You can find an example of this in the Java Developer's Journal in a class called JMaskField by Claude Duguay (Vol: 04 Issue: 01) see http://www.sys-con.com/java/index2.html
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.