This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Special characters in Java

 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell us which regex you were using.
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.regex.pattern and declared something like this..
private static final Pattern objRegexAlphanumericPattern = Pattern.compile("^[ A-Za-z0-9 ]+$");
 
Henry Wong
author
Marshal
Pie
Posts: 20995
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic