File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Special characters in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Special characters in Java" Watch "Special characters in Java" New topic
Author

Special characters in Java

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
How do I validate a string to verify whether it can have only Alphabets + numbers + special characters and not only numbers and not only special characters..

I tried with the regec pattern. I am able to validate for only numbers but not for others. anyone advise
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Please tell us which regex you were using.
rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
java.util.regex.pattern and declared something like this..
private static final Pattern objRegexAlphanumericPattern = Pattern.compile("^[ A-Za-z0-9 ]+$");
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19064
    
  40

The regex you are using only specifies letters and numbers -- which leads to the next question.... what "special" characters are you trying to specify.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
You will have to check with the Pattern class or the Java™ Tutorials, but I think that will match the 26 letters (upper-case and lower-case) used in English and ten digits and ordinary spaces, but no punctuation or accented letters, for the whole of a line from the ^ to the $.

And Henry has beaten me to it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Special characters in Java