Thursday, 20 February 2014

How to Restrict User to Enter Only Numbers in Asp.Net Textbox Using Javascript

In this article i will show you how you can restrict your user to add only a number in an asp.net textbox. This will also help you to restrict user to enter only digits or mobile number in textbox using javascript.
Here is the code to perform this operation. 
Allow Only Numbers

Allow only number

 
Here is the javascript code which is responsible for allowing adding only number in a textbox.
function CheckNumber(evt)
{
  var charcode=(evt.which)?evt.which:event.keycode;
  if(charcode>31 && (charcode < 48 || charcode >57 ))
   {
     return false;
   }else
   {
    return true;
   }
}

 








Tags: Ajax Control , Asp.Net , Ext Js , Javascript , jQuery , jQuery Mobile , MVC

No comments:

Post a Comment