| 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: 32689
|
|
|
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: 16695
|
|
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: 32689
|
|
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
|
 |
 |
|
|
subject: Special characters in Java
|
|
|