aspose file tools*
The moose likes Beginning Java and the fly likes How to check whether the input string contains numbers,comma,colon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to check whether the input string contains numbers,comma,colon" Watch "How to check whether the input string contains numbers,comma,colon" New topic
Author

How to check whether the input string contains numbers,comma,colon

Santhana Lakshmi.S
Ranch Hand

Joined: Aug 16, 2005
Posts: 82
HI,
In my project i want to check whether the user's input string contains numbers,commma,colon,double and single quotes and also any special characters
Iam getting the user input as a string.
Can anyone tell me how to check for this?

Thanks a lot.
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
Refer Regex package along with tutorial

The pattern expression would be something like this : [^a-zA-Z]

i.e. any character other than a to z and A to Z


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Santhana Lakshmi.S
Ranch Hand

Joined: Aug 16, 2005
Posts: 82
hi
Thanks a lot for your reply.
If you dont mind can you explain it with an example or sample code.
Thanks a lot
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Moving to Java In General (the best place to ask about string handling questions).


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Santhana Lakshmi.S
Ranch Hand

Joined: Aug 16, 2005
Posts: 82
hi
If i java.util.regex class i need to give the pattern where the special characters will occur.Am i right?
But in my case, the input string is user defined one.
In that,at any place the special characters and numbers will occur.
How to check those?
Thanks in advance
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
If I can repharse your requirement, it will be " To check whether the user input contains anything else other than a to z or A to Z characters"

Here anything else are numbers,colon,double,special characters etc

So you create a pattern to get all the matches that does not contain a-z or A-Z. After you compile the pattern, the matches should return only those values that do not contain a-z / A-Z which will be special chars, numbers, colons etc.

So I suggested the pattern would be [^a-zA-Z]
^ symbol is not negation.

For concrete examples refer tutorial link / API reference
Mike Noel
Ranch Hand

Joined: Dec 15, 2005
Posts: 108
Originally posted by Santhana Lakshmi.S:
hi
If i java.util.regex class i need to give the pattern where the special characters will occur.Am i right?
But in my case, the input string is user defined one.
In that,at any place the special characters and numbers will occur.
How to check those?
Thanks in advance


Regular expression syntax allows you to specify the characters without worrying about their exact placement in the string. For instance the pattern [a-z]* matches zero or more lower case letters. It doesn't matter what order the letters are in.


Mike Noel
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
do a switch statement...

like:



then you could,


[ July 17, 2006: Message edited by: Justin Fox ]

You down with OOP? Yeah you know me!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to check whether the input string contains numbers,comma,colon
 
Similar Threads
Whitespace deletion
Ant installation (problem running ANT)
Type checking
checking type
Type checking