0

我有一个文本字段。我想让这个字段只接受 10 位数字,如果输入的数字大于 10 或小于 10,则抛出错误

<td><input name="Number" type="text" id="Number" value="" required/></td>

    document.getElementById('Number').onchange = function()
    {
          if(this.value > 11){
               this.value = "Please Check the Ticket Number Again";
          }
          if(this.value < 10){
               this.value = "Please Check the Ticket Number Again";
          }
    }
4

1 回答 1

1

试试这个代码:

<td><input name="Number" type="text" id="Number" value="" required/></td>

    document.getElementById('Number').onchange = function()
    {
          if(this.value.length != 10){
               this.value = "Please Check the Ticket Number Again";
          }

    }
于 2013-06-24T07:22:17.083 回答