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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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.
 
Don't get me started about those stupid light bulbs.
 
subject: Validating Time Format (HH:MM:SS)