aspose file tools
The moose likes Beginning Java and the fly likes non alpa characters in a string?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "non alpa characters in a string??" Watch "non alpa characters in a string??" New topic
Author

non alpa characters in a string??

slim warren
Greenhorn

Joined: Aug 28, 2001
Posts: 1
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
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.
 
subject: non alpa characters in a string??
 
Similar Threads
Struts Loop breaks at specific number of characters
Deleting Characters
How many String Object are created in the following code ??
Doubt regarding the implementation class!!
Smarter Charset Conversion