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

解决方案 »

  1.   


    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;
        }
    }
      

  2.   


    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;
    }
    看看执不执行
      

  3.   

    汗,少写了一个括号:
    else if(!txtUserAccount.value.match(/^\d{1,7}$/))