2016-06-07 42 views
-1

我有一個文本框我想禁用字母鍵和特殊鍵...... 只是想輸入數字鍵(0-9)。 如果我按任何字母鍵,文本框保持空白,請勿事件鍵入除0-9之外的任何字符。 告訴我,我應該使用什麼..如何禁用字母鍵使其不能鍵入

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
             ErrorMessage="!" ValidationExpression="^[0-9]+$" ControlToValidate="txtboxGAmountC"></asp:RegularExpressionValidator> 

允許輸入所有字符後,它給出的錯誤信息...... 我甚至不想要輸入任何字符,除了0-9 ... 建議我......

+0

使用html輸入標籤並使用type =「number」 –

回答

0
You can do with using javascript function 
function validateNumber(key) 
{ 
//getting key code of pressed key 
var keycode = (key.which) ? key.which : key.keyCode; 
var phn = document.getElementById('Idof text box'); 
//comparing pressed keycodes 
if (!(keycode==8 || keycode==46)&&(keycode < 48 || keycode > 57)) 
{ 
return false; 
} 
else 
{ 
//Condition to check textbox contains ten numbers or not 
if (phn.value.length <10) 
{ 
return true; 
} 
else 
{ 
return false; 
} 
} 
} 
0

我不太瞭解ASP,但如果鍵入的字符不是數字,將不會捕獲按鍵事件並取消它,

+0

在visual basic中,有一個內置函數禁用鍵。 我認爲必須在asp.net中 –