验证HH:MM时间 [英] Validate a HH:MM time

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

问题描述

这是我的javascript示例.怎么可以即兴创作呢?

This is my javascript sample. How can it be improvised?

function a(id) 
{
    var n=document.getElementById(id);
    var re=/^[0-9]:[0-9] [to] [0-9]:[0-9]*$/;

    if(re.test(n.value))
    {
        n.style.backgroundColor="#52F40C";
    }
    else
    {
        window.alert("Invalid Entry");
        n.style.backgroundColor="#F40C0C";
        n.focus();
        n.value="";
    }
}

我想验证用户输入,例如10:30到12:30.我比较新鲜,请建议我.

I wanna validate user input which should be for example 10:30 to 12:30. I'm a fresher please suggest me.

推荐答案

将此正则表达式用于时间格式hh:mm

Use this regex for time format hh:mm

^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$

我刚刚放置了时间格式.请尝试根据您的要求进行编辑.

I have just placed the time format.Try to edit this for your requirement.

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

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