Jquery tutorials limit text boxes to Numbers and decimal point examples to share

  • 2020-03-30 01:19:10
  • OfStack


$(function(){     
              
            $(".NumText").keyup(function(){    
                    $(this).val($(this).val().replace(/D|^0/g,''));  
                }).bind("paste",function(){  //CTR+V event handling & NBSP;    
                    $(this).val($(this).val().replace(/D|^0/g,''));     
                }).css("ime-mode", "disabled"); //CSS Settings input method not available & NBSP;    

              
            $(".NumDecText").keyup(function(){    
                    $(this).val($(this).val().replace(/[^0-9.]/g,''));    
                }).bind("paste",function(){  //CTR+V event handling & NBSP;    
                    $(this).val($(this).val().replace(/[^0-9.]/g,''));     
                }).css("ime-mode", "disabled"); //CSS Settings input method not available & NBSP;    
        });  

Then add the class name to the text box that needs to be validated, like this:


<input type="text" class="txt NumText"  Width="100px"  runat="server" />


Related articles: