2013-06-24 149 views
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"; 
      } 
    } 

回答

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

    } 
+0

Worked..Thanks一很快。那很快.. :) – Pete