asp文本框只接受IE8中的字符

时间:2014-02-21 17:21:19

标签: javascript internet-explorer-8 textbox ie8-compatibility-mode

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

它适用于chromefirefox,但在IE8中不起作用。

我能做些什么让它发挥作用?

1 个答案:

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