如何检查组合键 [英] how to check for the key combination

查看:106
本文介绍了如何检查组合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我需要验证以下形式的手机号码,我需要限制用户不要按spcl字符和字母..now以获取@ @ spcl字符,例如,我应该如何与e.KeyCode或e.KeyValue ..或什么

hi all ,
I need to validate the form where for mobile number i need to restrict user from pressing spcl chars and alphabets ..now for spcl chars like @ how should i compare with e.KeyCode or e.KeyValue ..or what

推荐答案

可以通过以下方式在脚本标记中进行检查,并在如下所示的keyupevent上调用它,

do by checking it this way inside script tag and call it on keyupevent like below,

<SCRIPT language=Javascript>

      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
    {

        alert("please insert only numeric values");
            return false;

    }
    else
    {
         return true;
    }
      }
   </SCRIPT>





<INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar">


这篇关于如何检查组合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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