用JS 怎么限制用户输入玩家ID的时候 不能输入汉字,并且只能是7位以下的数字呢?
比如我在这段代码上加,该如何加呢?
function checkInutAndPrompt()
{
var txtUserAccount=document.getElementById("<% =txtUserAccount.ClientID %>");
if(txtUserAccount.value=="")
{
alert("请输入玩家帐号ID!");
txtUserAccount.focus();
return false;
}
}
比如我在这段代码上加,该如何加呢?
function checkInutAndPrompt()
{
var txtUserAccount=document.getElementById("<% =txtUserAccount.ClientID %>");
if(txtUserAccount.value=="")
{
alert("请输入玩家帐号ID!");
txtUserAccount.focus();
return false;
}
}
function checkInutAndPrompt()
{
var txtUserAccount=document.getElementById(" <% =txtUserAccount.ClientID %>");
if(txtUserAccount.value=="")
{
alert("请输入玩家帐号ID!");
txtUserAccount.focus();
return false;
}
else if(!txtUserAccount.value.match(/^\d{1,7}$/)
{
alert('请输入7位以下数字');
txtUserAccount.focus();
return false;
}
}
function checkInutAndPrompt()
{
var txtUserAccount=document.getElementById(" <% =txtUserAccount.ClientID %>");
if(txtUserAccount.value=="")
{
alert("请输入玩家帐号ID!");
txtUserAccount.focus();
return false;
}
else if(!txtUserAccount.value.match(/^\d{1,7}$/)
{
alert('请输入7位以下数字');
txtUserAccount.focus();
return false;
}
alert("输入格式正确");
return true;
}
看看执不执行
else if(!txtUserAccount.value.match(/^\d{1,7}$/))