File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Validating Time Format (HH:MM:SS)" Watch "Validating Time Format (HH:MM:SS)" New topic

Validating Time Format (HH:MM:SS)

Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141

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 ???

SCJP 1.4
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257


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

More inputs are welcome.
I agree. Here's the link:
subject: Validating Time Format (HH:MM:SS)
It's not a secret anymore!