Please enable Javascript to correctly display the contents on Dot Net Tricks!

Restrict user to enter numeric value in textbox using javascript

  Author : Shailendra Chauhan
Updated On : 29 Jan 2013
Total Views : 14,160   
 

Due to some reasons (like don’t allow to enter chars in Price TextBox), we restrict users to enter chars in TextBox. We can implement this functionality by using below method.

 <script type="text/javascript">
 function checkNumeric(event) {
var kCode = event.keyCode || event.charCode; // for cross browser check

//FF and Safari use e.charCode, while IE use e.keyCode that returns the ASCII value 
if ((kCode > 57 || kCode < 48) && (kCode != 46 && kCode != 45)) {
//code for IE
 if (window.ActiveXObject) {
 event.keyCode = 0
 return false;
 }
else
{
 event.charCode= 0
}
 }
}
</script>

<asp:TextBox ID="TextBox1" runat="server" onkeypress="return checkNumeric(event); ></asp:TextBox> 
YOU MIGHT LIKE
Free Interview Books
 
COMMENTS (0)
14 DEC
ASP.NET MVC with AngularJS Development (online)

MON-FRI 07:30 AM- 09:00 AM IST

Know More
5 DEC
AngularJS Development (online)

Mon - Fri     6:30 AM-7:30 AM IST

3 DEC
AngularJS Development (offline)

SAT,SUN     11:00 AM-12:30 PM IST

3 DEC
MEAN Stack Development (offline)

Sat, Sun     (09:30 AM-11:00 AM IST)

26 NOV
ASP.NET MVC with AngularJS Development (offline)

(SAT,SUN)     03:30 PM-05:00 PM IST

24 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     09:30 PM-11:00 PM IST

12 NOV
ASP.NET MVC with AngularJS Development (offline)

SAT,SUN     08:00 AM-09:30 AM

3 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     07:30 AM-09:00 AM IST

25 OCT
.NET Development (offline)

Mon-Fri     9:00 AM-11:00 AM IST

BROWSE BY CATEGORY
 
RECENT ARTICLES
SUBSCRIBE TO LATEST NEWS
 
LIKE US ON FACEBOOK
 

Professional Speaks

+