Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2005

Tip: Looking for answers? Try searching our database.

check string for different criteria

Thread view: 
Frank Meyer - 27 May 2005 16:08 GMT
Hi newsgroup,

not only that I have some trouble with my ArrayLists, I also need to check
Strings.

The problem is that I will have to check around 100 string if they meet the
specific criteria as follows:

XXX-000000

which means they have to start with three capital letters followed by a
hyphen and a six-digit number.

If anyone knows anything, I would be really thankful.

Once again best regards

Frank
Roland - 27 May 2005 17:04 GMT
> Hi newsgroup,
>
[quoted text clipped - 14 lines]
>
> Frank

Use a regular expression: [A-Z]{3}-\d{6}

In a Java string literal you have to escape the backslash, so this would
become

if (  Pattern.matches("[A-Z]{3}-\\d{6}", theStringToCheck) ) {
   // accepted
} else {
   // rejected
}

<http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html>
Signature

Regards,

Roland de Ruiter
  ___      ___
 /__/ w_/ /__/
/  \ /_/ /  \

Frank Meyer - 27 May 2005 17:35 GMT
Roland,

> Use a regular expression: [A-Z]{3}-\d{6}

once again: heavy thanks :o)

Best regards

Frank


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.