Php验证24小时时间格式 [英] Php validating 24 hour time format

查看:191
本文介绍了Php验证24小时时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许用户从 00:00:00 选择一个小时到 23:00:00 并且需要检查它们是否提交正确的格式。是否有正则表达式或php函数验证24小时格式,例如 HH:MM:SS

I'm allowing users to pick an hour from 00:00:00 to 23:00:00 and need to check if they submit the right format. Is there a regular expression or php function that validates a 24 hour format e.g. HH:MM:SS?

我发现了一些正则表达式,但是我验证的24小时时间总是设置为 00 几分钟和几秒钟。只有一小时不一。

I found some regex examples but the 24 hour time I'm validating is always set to 00 for minutes and seconds. Only the hour varies.

例如

18:00:00, 23:00:00, 01:00:00


推荐答案

小时时间包括秒

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

想要00分钟和秒,然后

If you only want 00 for minutes and seconds, then

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

这篇关于Php验证24小时时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆