启用Numlock时如何获取ASCII值 [英] how to get ASCII values when Numlock is on

查看:77
本文介绍了启用Numlock时如何获取ASCII值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个文本框,我可以验证以仅接受字符串值.但是当Numlock处于打开状态时,它可以接受数字以及字符串值.
我只希望如果启用Numlock,它将不接受数值

代码在这里:

Hello All,
I have a Text Box which I have Validate to accept only string Values.But when Numlock is on it accepts numeric as well as string values.
I want only that if Numlock is on,it will not accept the numeric values

code is here :

<script type="text/javascript" language="javascript">
function isString(keyCode)
{
    return ((keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) ||keyCode==8 ||keyCode==32)
}
</script>


所以怎么可能


so how it will be possible

推荐答案

尝试此代码.

Try this code.

function isString(textObj) {
   var newValue = textObj.value;
   var newLength = newValue.length;
   var extraChars=". -,";
   var search;
   for(var i = 0; i != newLength; i++) {
      aChar = newValue.substring(i,i+1);
      aChar = aChar.toUpperCase();
      search = extraChars.indexOf(aChar);
      if(search == -1 && (aChar < "A" || aChar > "Z") ) {
         return false;
      }
   }
   return true;
}





HTH





HTH


这篇关于启用Numlock时如何获取ASCII值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆