1. simply use a textbox control, and put a regular expression validator on this box.. with regular expression as \d+.. and you are done..
2. use a simple javascript function to do the same, and grab the keypress event for the box..
function blockNumber(e)
{
      var keychar;
      var reg;
      keychar = String.fromCharCode(e.keyCode);
      reg = /\d/;
      return reg.test(keychar);
}
this function will block user from entering any character other then numbers.. add this function call as attribute for onkeypress event...
txtMyBox.Attributes.Add("onkeypress", "return blockNumber(event);");
and you are done..
isn't this simple or what!!! :)
 
The above provided javascript works with IE, and fail in Firefox. Textboxes on which the script is hooked will not be able to accept any input, be it character or numeric value.
ReplyDeletewill keep you guys posted on the fix..
Regards
Nitin