如何限制文本框只输入带有+ - 和数字的数字。 [英] How to restrict text box to enter only numerics with + - and .

查看:58
本文介绍了如何限制文本框只输入带有+ - 和数字的数字。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在onkeydown和onpress事件上写了一个函数

如下所示

Iam writing a function on onkeydown and onpress event
like below

function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57&& charCode != 190 && charCode != 110 && (charCode > 105 || charCode < 96||))
            return false;

         return true;
      }





它正在访问数字键盘的 + - 但是当我尝试时从keybord padds输入+和 -

即使用shift + = for plus和shift + - 对于减号

它不允许输入 + - 因为事件是在按下shift时触发,只有如何使文本框允许数字qith加号和减号使用键盘



It is accessing + and - of the number pad but when am trying to enter + and - from keybord padds
i.e by using shift + = for plus and shift +- for minus
it is not allowing to enter + and - because the event is firing on pressing of shift only how to make text box to allow numbers qith plus and minus symbol using key board

推荐答案

在允许的字符中,你将也必须允许代码15。
In the allowed characters, you will have to allow the code 15 as well.


使用 RegExp 代替。



请关注这些,

http://www.w3resource.com/javascript/form/all -numbers.php [ ^ ]

http://www.dotnetspider.com/f orum / 311120-Validate-textbox-accept-only-numbers-alphabets -whitespace-plus-symbol-minus-symbol-dot-col.aspx [ ^ ]



-KR
Use RegExp instead.

Please follow these,
http://www.w3resource.com/javascript/form/all-numbers.php[^]
http://www.dotnetspider.com/forum/311120-Validate-textbox-accept-only-numbers-alphabets-whitespace-plus-symbol-minus-symbol-dot-col.aspx[^]

-KR


这篇关于如何限制文本框只输入带有+ - 和数字的数字。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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