Regex for hour, minute and second format HH:MM:SS -



Regex for hour, minute and second format HH:MM:SS -

im trying implement regex hh:mm:ss, example:

07:15:30

but can't work

right im using:

([01]?[0-9]|2[0-3]):[0-5][0-9]

any clue?

^(?:([01]?\d|2[0-3]):([0-5]?\d):)?([0-5]?\d)$

explanation:

^ # start of string (?: # seek match ([01]?\d|2[0-3]): # hh: ([0-5]?\d): # mm: )? # (entire group) ([0-5]?\d) # ss $ # end of string

used expressions regex cheat sheet here:

http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/

edit #1

^(?:([01]?\d|2[0-3]):([0-5]?\d):)?([0-5]\d)$

removed ? on ss create homecoming false if 1 digit entered seconds.

edit #2

^([0-5]\d):([0-5]\d):([0-5]\d)$

changed hh part little if user types hh without mm , ss, returns false.

edit #3

thanks comment look add together list

^((?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$)

regex

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -