我有asp:TextBox
,我需要验证只接受字符。
文本框
<asp:TextBox runat="server" id="txt" onkeypress="return AllowAlphabet(event)" />
的Javascript
function AllowAlphabet(e)
{
isIE = document.all ? 1 : 0
keyEntry = !isIE ? e.which : event.keyCode;
if (((keyEntry >= '65') && (keyEntry <= '90')) || ((keyEntry >= '97') && (keyEntry <= '122')) || (keyEntry == '46') || (keyEntry == '32') || keyEntry == '45')
return true;
else
{
alert('Please Enter Only Character values.');
return false;
}
}
它适用于chrome
,firefox
,但在IE8
中不起作用。
我能做些什么让它发挥作用?
答案 0 :(得分:0)
这不适合你吗?
function AllowAlphabet(e) {
e = e || window.event;
var keyEntry = e.which || e.keyCode;
var bIsCharacter =
(keyEntry >= 65 && keyEntry <= 90) ||
(keyEntry >= 97 && keyEntry <= 122) ||
(keyEntry == 46) ||
(keyEntry == 32) ||
(keyEntry == 45);
return bIsCharacter;
}