Introduction
This tutorial explains how to only allow a number in textbox using jQuery. If you simply add the 'numberonly' class to the text control, then it will only allow numbers.
Code
- $(document).ready(function () {
- $('.numberonly').keypress(function (e) {
- var charCode = (e.which) ? e.which : event.keyCode
- if (String.fromCharCode(charCode).match(/[^0-9]/g))
- return false;
- });
- });
Join the conversation! Your thoughts help the community grow.