尝试检查输入文本框的时间
我必须对问题进行概述,并且用户必须能够插入时间。 为此,我创建了 2 个文本框,1 个用于小时输入,1 个用于分钟输入。
我现在想做的是检查这些值是否太高而不是正确的。
示例:
小时值不能高于 23,分钟值不能高于 59。
检查此值的最佳方法是什么?
我一直在考虑 if 语句,但也许有一种更有效的方法来完成这个任务?
也许是正则表达式,尽管我不知道这件事的正确语法。
提前致谢。
I have to make this overview of questions and the user has to be able to insert a time.
To do this I made 2 textboxes, 1 is for the hour input and 1 is for the minute input.
What I want to do now is check if the values aren't to high to be correct.
Example:
The hour value cant be higher than 23 and the minute cant be higher than 59.
What is the best method for checking this?
I've been thinking about if statements but maybe there is a much more efficient way to get this done?
Maybe regular expressions, although I wouldnt know a correct syntax for this matter.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它必须是正则表达式:
将验证小时并
验证分钟。
“Hours”正则表达式的解释:(您可以自己轻松计算出分钟数):
If it has to be a regex:
will validate the hour and
will validate the minute.
Explanation for the "Hours" regex: (you can figure out the minutes yourself easily):
if 语句绝对是正确的选择。没有理由对如此简单的事情使用正则表达式......这就像使用大锤将小钉子钉入墙上一样。 If 语句也非常高效且易于阅读...没有理由使用正则表达式来完成您正在做的事情。
If statements are definitely the way to go. There's no reason to use a regular expression for something so simple... it's like using a sledgehammer to place a small nail into a wall. If statements are also very efficient and easy to read... there's no reason to use regex for what you're doing.