Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 578
  • Last Modified:

Regular expression to validate time

Hi,

I wanted to validate time by regular expression in hh:mm:ss format

for example 16:12:18 is valid time

The below reqular expression is not working good

^([0]\d|[1][0-2])\/([0-2]\d|[3][0-1])\/([2][01]|[1][6-9])\d{2}(\s([0]\d|[1][0-2])(\:[0-5]\d){1,2})*\s*([aApP][mM]{0,2})?$

Can you please help me in fixing the regular expression

User has to enter time in hh:mm:ss format only

Many Thanks
0
tia_kamakshi
Asked:
tia_kamakshi
2 Solutions
 
Patrick MatthewsCommented:
^(2[0-3]:[0-5]\d:[0-5]\d|[0-1]\d:[0-5]\d:[0-5]\d$
0
 
Patrick MatthewsCommented:
Sorry, I was missing a ) right before the $
0
 
pauloaguiaCommented:
How about
^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9]):([0-5]?[0-9])$
?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
tia_kamakshiAuthor Commented:
Many Thanks for your quick response
0
 
Hugh FraserConsultantCommented:
Don't forget to include the 1:23:45 format (no leading 0).

/2[0-3]:[0-5]\d:[0-5]\d|[0-1]\d:[0-5]\d:[0-5]\d|\s\d:[0-5]\d:[0-5]\d/
0
 
pauloaguiaCommented:
> Don't forget to include the 1:23:45 format (no leading 0).
Yes, that's supported in the expression I posted above ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now