Home > ASP.Net, Javascript > Allow Number Only In ASP.Net TextBox

Allow Number Only In ASP.Net TextBox


Hi all ,

try this example to allow number only in ASP.Net TextBox control according to user btowser

Javascript Code :


function CheckNumberOnly(e) {
 var unicode = e.keyCode ? e.keyCode : e.charCode;
 if (navigator.appName == 'Microsoft Internet Explorer') {
 if ((unicode == 9 /*TAB*/) || (unicode == 8/*BackSpace*/) || (unicode >= 48 && unicode <= 57) || (unicode == 96)) {
 return true;
 }
 else {
 return false;
 }
 }
 else {
 if ((event.keyCode >= 48 && event.keyCode <= 57) ||
 event.keyCode == 8/*BackSpace*/ || event.keyCode == 9 /*TAB*/ || event.keyCode == 37 ||
 event.keyCode == 39 || event.keyCode == 190) {
 return true;
 }
 else {
 return false;
 }
 }
}

In Code behind :

TextBox1.Attributes.Add("onkeypress", "return CheckNumberOnly(event)");

also you can check this post

Make TextBox accept Number only

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net, Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: