Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Sunday, 5 January 2020

Only allowed number in textbox using jquery

Introduction
Only allowed number in textbox using jquery.  Add 'numberonly' class to text control then it will only allow number.
 
Code  

  1. $(document).ready(function () {          
  2.             $('.numberonly').keypress(function (e) {          
  3.                 var charCode = (e.which) ? e.which : event.keyCode          
  4.                 if (String.fromCharCode(charCode).match(/[^0-9]/g))         
  5.                     return false;                              
  6.             });          
  7.         });