Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 仅当我在chrome调试器中附加了断点时,时间验证输入才有效_Javascript_Html - Fatal编程技术网

Javascript 仅当我在chrome调试器中附加了断点时,时间验证输入才有效

Javascript 仅当我在chrome调试器中附加了断点时,时间验证输入才有效,javascript,html,Javascript,Html,我有一些代码,我想验证输入,我想创建自己的时间验证器,而不是在输入上使用时间类型,因为我也在设计它的样式 但是,当前代码不允许解析任何所需的字符[A-Z],除非我在if语句上设置断点 要添加到该项中以将值转换为始终格式化的时间(00:00和25:93>23:59) window.validateTimeInput=函数(evt){ var e=evt | | window.event, key=e.keyCode | e.which, keyChar=String.fromCharCode(键)

我有一些代码,我想验证输入,我想创建自己的时间验证器,而不是在输入上使用时间类型,因为我也在设计它的样式

但是,当前代码不允许解析任何所需的字符[A-Z],除非我在if语句上设置断点

要添加到该项中以将值转换为始终格式化的时间(00:00和25:93>23:59)

window.validateTimeInput=函数(evt){
var e=evt | | window.event,
key=e.keyCode | e.which,
keyChar=String.fromCharCode(键),
regexChars=/[0-9]|\:/,
regexActions=/37 | 38 | 39 | 40 | 46 | 27 | 13 | 8///左、上、右、下、删除、转义、回车、退格
//这里的断点
if((regexChars.test(keyChar)?false:!regexActions.test(key.toString())&&e.target.value.length>=5){
e、 returnValue=false;
如果(e.preventDefault())e.preventDefault();
//返回false;
}
};
例如:

试着从if语句中抽出这一行,看看这是否有助于缩小范围。你也可以把支票分开一点,而不是把它们都放在一行

$foo = regexChars.test(keyChar) ? false : !regexActions.test(key.toString();
if($foo){
    ...
}

问题是您的正则表达式:
/37 | 38 | 39 | 40 | 46 | 27 | 13 | 8/
。太宽了

它允许字母“r”,键码82。因为
/8/
允许字符串
“82”
。(还允许使用字母dnpqrstuvwxyDNPQRSTUVWXY。)

将您的正则表达式更改为:

 /^(37|38|39|40|46|27|13|8)$/

var regexp1=/^[0-2]{1}/;
var regexp2=/^[0-9]{2}/;
var regexp3=/^[0-9]{2}\:{1}/;
var regexp4=/^[0-9]{2}\:{1}[0-5]{1}/;
var regexp5=/^[0-9]{2}\:{1}[0-9]{2}$/;
$(函数(){
$(“:text”).keyup(函数(evt){
var curent=$(此);
if(curent.val().length==1)
{
if(regexp1.test(curent.val()))
{
}
其他的
{
当前值(“”);
}
}
else if(curent.val().length==2)
{
if(regexp2.test(curent.val())和&curent.val()<24)
{
}
其他的
{
curent.val(curent.val().slice(0,1));
}
}
else if(curent.val().length==3)
{
if(regexp3.test(curent.val()))
{
}
其他的
{
curent.val(curent.val().slice(0,2));
}
}
else if(curent.val().length==4)
{
if(regexp4.test(curent.val()))
{
}
其他的
{
curent.val(curent.val().slice(0,3));
}
}
else if(curent.val().length==5)
{
if(regexp5.test(curent.val()))
{
}
其他的
{
curent.val(curent.val().slice(0,4));
}
}
否则如果(curent.val().length>5)
{
curent.val(curent.val().slice(0,5));
}
});
});

尝试了这一点,但只有在if语句上放置断点时,相同的结果仍然有效。尝试了这一操作,但仅在if语句上放置断点时仍然有效。创造了一个小提琴来显示我的观点太哈!您应该将
16
添加到正则表达式列表中。换档键!嗯,这似乎也不管用。另一种方法是,假设你的用户不紧张,稍后再验证输入。不需要时间验证的解决方案。另外,我将在“已更改”而不是“按下键”的情况下处理该问题。由于某种原因,我一直在验证密钥。我已经修改了脚本,现在只允许有效时间23:59
 /^(37|38|39|40|46|27|13|8)$/
<?php
// $hd = curl_init("http://www.laleo.com/ebooks_android/ebooks_search_json.php");
// curl_setopt($hd,CURLOPT_POSTFIELDS,"query=deporte");
// curl_exec($hd);
// curl_close($hd);
?>
<html>
<head>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var regexp1 = /^[0-2]{1}/;
var regexp2 = /^[0-9]{2}/;
var regexp3 = /^[0-9]{2}\:{1}/;
var regexp4 = /^[0-9]{2}\:{1}[0-5]{1}/;
var regexp5 = /^[0-9]{2}\:{1}[0-9]{2}$/;
$(function(){

    $(":text").keyup(function(evt){
    var curent = $(this);
    if(curent.val().length == 1)
    {
        if(regexp1.test(curent.val()))
        {

        }
        else
        {
            curent.val("");
        }
    }
    else if(curent.val().length == 2)
    {
        if(regexp2.test(curent.val()) && curent.val() < 24)
        {

        }
        else
        {
            curent.val(curent.val().slice(0,1));
        }
    }
    else if(curent.val().length == 3)
    {
        if(regexp3.test(curent.val()))
        {

        }
        else
        {
            curent.val(curent.val().slice(0,2));
        }
    }
    else if(curent.val().length == 4)
    {
        if(regexp4.test(curent.val()))
        {

        }
        else
        {
            curent.val(curent.val().slice(0,3));
        }
    }
    else if(curent.val().length == 5)
    {
        if(regexp5.test(curent.val()))
        {

        }
        else
        {
            curent.val(curent.val().slice(0,4));
        }
    }
    else if(curent.val().length > 5)
    {
        curent.val(curent.val().slice(0,5));
    }
    });

});
</script>
</head>
<body>
    <input type="text" />
</body>
</html>