Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
HTML
<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>




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>
Posted
Updated 11-Apr-16 21:03pm

1 solution

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

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


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900