File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How do i check for special characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do i check for special characters " Watch "How do i check for special characters " New topic

How do i check for special characters

Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155

How do i check whether a string has special characters or not

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
More of a beginners' question.
What do you mean by special characters?
Suggest you split the String into a char[] array and use the methods of the Character class on the individual chars.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
The character-by-character approach will work.

An alternative would be to use a regular expression, via java.util.regex.Pattern. If you look up the API doc for Pattern, you will see that there are a wide variety of character classes on which you can match.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I agree. Here's the link:
subject: How do i check for special characters
It's not a secret anymore!