The following piece of code can be used in textbox keypress event to restrict user to enter only numbers.