File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Validating Time Format (HH:MM:SS) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Validating Time Format (HH:MM:SS)" Watch "Validating Time Format (HH:MM:SS)" New topic
Author

Validating Time Format (HH:MM:SS)

Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141
Hi,

I m trying to validate Time which is HH:MM:SS format. But not able to do it.

Suppose input = 34:67:78
String pat = " ( [0-1]+[0-9]+) |([2][0-3]+) : ( [0-5]+[0-9]+) : ([0-5]+[0-9]+ ) ";
Pattern p = Pattern.compile(pat);

Its validating this input...

Plzz tell me wat is wrong in this ???


rawat
SCJP 1.4
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,

The + after the [] is making one or more cases. Remove + it will work.

More inputs are welcome.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Validating Time Format (HH:MM:SS)
 
Similar Threads
problem in getting date and time in textbox
time comparison between given periods
REGEX Help
Current time
how to get the last modified time of a text file