当我动态添加数字验证时,数字验证无法在输入类型文本中使用 [英] Numeric validation not working in input type text when I add them dynamically

查看:75
本文介绍了当我动态添加数字验证时,数字验证无法在输入类型文本中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javascript添加这些文本框dynamiccaly。我希望这些文本框只能采用数值,但验证javascript不适合他们..



这是我的设计..我在里面显示文本框modal然后逐个递增。

I add these text boxes dynamiccaly by using javascript. I want these text boxes has to take only numeric values, but validation javascript not working for them..

Here is my Design.. I display the text box inside a modal then increment them one by one.

<div class="modal-content">
                           <div class="modal-header">
                               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                               <h4 class="modal-title">ADD PHONE NUMBERS</h4>
                           </div>
                           <div class="modal-body">
                               <p>Please  add  alternate phone numbers:</p>

                               <div class="phoneDiv">

                                   <div class="phoneRow">
                                       <input class="form-control input-sm" id="setPhone0" maxlength="14" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" />
                                       <span class="removeThis">X</span>
                                   </div>

                               </div>
                               <button class="btn btn-link showLinkbutton" type="button"><i class="glyphicon glyphicon-plus-sign"></i>Add More</button>


                               <div class="clear"></div>

                           </div>
                           <div class="modal-footer text-center">

                               <button type="button" class="btn btn-info" id="submitPhoneNumbers">Save changes</button>
                               <button type="button" id="btnClose" class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button>
                           </div>
                       </div>









谢谢&问候

Bigyan Sahoo



我尝试过:



javascript验证码



< script type =text / javascript>

函数IsNumeric(e){

var keyCode = e.which? e.which:e.keyCode

var ret =((keyCode> = 48&& keyCode< = 57)|| specialKeys.indexOf(keyCode)!= -1);

返回ret;

}



< / script>





Thanks & regards
Bigyan Sahoo

What I have tried:

javascript validation code

<script type="text/javascript">
function IsNumeric(e) {
var keyCode = e.which ? e.which : e.keyCode
var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
return ret;
}

</script>

推荐答案

您当前的代码仅使用键盘顶部输入的数字,而不是数字键盘上的数字



Your current code only uses numbers entered at the top of the keyboard not on the numeric keypad

if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105))   return true;
return false;





什么是specialKeys应该做的?我假设其字符数组如。, -



What is specialKeys supposed to do? I assume its array of characters like ".", "-"


这篇关于当我动态添加数字验证时,数字验证无法在输入类型文本中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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