aspose 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
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.
 
wood burning stoves
 
subject: Validating Time Format (HH:MM:SS)