gpt4 book ai didi

javascript 表单验证文本字段长度

转载 作者:行者123 更新时间:2023-11-28 20:20:57 24 4
gpt4 key购买 nike

我在验证学生证时遇到问题,它需要 10 个数字,我遇到的问题是当我输入有效的学生证时,它仍然返回 false。请帮我检查一下mycoding,非常感谢。

我的学生 ID 示例 =“1101106363”

if ((document.appsub.id.value == "") || !(isNaN(document.appsub.id.value)) || (document.appsub.id.value.length < 11))
{
alert("Please enter the correct Student ID");
document.appsub.id.focus();
return false;
}

更新:[链接]http://jsfiddle.net/rVswq/1/

最佳答案

您需要使用document.getElementById方法来正确选择元素。

var el = document.getElementById("yourid");if (!(isNaN(el.value)) || (el.value.length < 11))    {        alert("Please enter the correct Student ID");        el.focus();        return false;    }

关于javascript 表单验证文本字段长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18332970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com