Wednesday, May 4, 2016

Jquery for check float numbers on keypress event

Script

 <script type="text/javascript">  
     $(document).ready(function () {  
 $('.isFloat').keypress(function(event) {  
  if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {  
   event.preventDefault();  
  }  
 });  
  });  
 </script>  

 <asp:TextBox ID="txtTotlaMark" runat="server" pattern="^[0-9 .]{1,}$" class="isFloat" MaxLength="6" required></asp:TextBox>  

Javascript function to check numbers on keypress event

Sctipt

 <script type="text/javascript">  
  function isNumber(evt) {  
       evt = (evt) ? evt : window.event;  
       var charCode = (evt.which) ? evt.which : evt.keyCode;  
       if (charCode > 31 && (charCode < 48 || charCode > 57)) {  
         return false;  
       }  
       return true;  
     }  
   </script>  

 <asp:TextBox ID="txtMobile" pattern="^[0-9+ ]{1,}$" runat="server" CssClass="form-control1" MaxLength="15" onkeypress="return isNumber(event);"  required></asp:TextBox>