I tried like this it is not working, but not works for value 005959 format HHMMSS
if(Pattern.matches("^([0-23])([0-59])([0-59])$", value))
{
SimpleDateFormat dformat = new SimpleDateFormat("HHMMSS");
dformat.setLenient(false);
dformat.parse(value);
return true;
}
You can’t do numeric ranges like that. To validate 1-24 (what’s wrong with 00 by the way? and since when was 60 valid in the other positions?) you’d need to do it digit by digit like this:
That is, if the first digit is 0 then 1-9 must follow; if 1 then any can follow; if 2 then 0-4 must follow. But why use Regex for this anyway? In full:
But still, check comments on 0 and 60 values…