This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring forum!
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.
jQuery in Action, 3rd edition
subject: Validating Time Format (HH:MM:SS)
It's not a secret anymore!