Showing posts with label Textbox. Show all posts
Showing posts with label Textbox. Show all posts

Friday, May 15, 2009

Accept Number Only

Hi, Today this is my first post in my asp.net topic (Even this year, this is my first post).

I will show on how to validate textbox input in numeric using javascript.

Step1:
function checkNum(event)
{
event = (event) ? event : window.event
var charCode = (event.which) ? event.which : event.keyCode
{
if ((charCode >= 48 && charCode <= 57) || (charCode == 8) || (charCode == 37) || (charCode == 39)) {
return true
}
return false
}

Step2:
In your form load event

txtnumeric.attributes.add("onKeyPress","return checkNum(event)")



This example showing that theirs another way to validate numeric input in a textbox.