![](/img/trans.png)
[英]Validating a textbox while typing special characters and having specific length
[英]Need Help Validating Textbox for Specific Length and content
我的.asp网页上有以下验证代码。 我还需要验证txtndc
textbox
以便输入的数据如下所示。 00000-0000当前,他们可以在此文本框中输入任何信息。 该条目应始终为5个破折号和4个数字。 任何帮助将不胜感激。
function form_onsubmit() {
if (form1.txtdrug.value == "")
{
alert("Drug Name Needed");
return false;
}
if (form1.txtndc.value == "")
{
alert("NDC Number Needed");
return false;
}
if (form1.txtndc.value != "" && form1.txtdrug.value != "")
{
alert("Drug was Successfully entered into the database, hit enter to continue.");
return true;
}
}
语法将如何编写。 我要检查的文本框是
<input type="text" name="txtndc" size="35">.
我不确定如何将下面的代码输入到我的页面中。 请帮忙
使用Javascript regex#test函数。
x = /^[0-9]{5}-[0-9]{4}$/;
console.log(x.test("12113-1234"));
>>> x = /^[0-9]{5}-[0-9]{4}$/; console.log(x.test("00000-0004"));
true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.