There are two basic approaches: for WinForms, I would strongly recommend using a
NumericUpDown class[
^] instead of a textbox - not only does it allow you to set a max and min value that is allowed, but it also converts to a number for you automatically.
For a web based solution, you are best with a Javascript solution of some kind. There is a good one here:
http://www.javascript-coder.com/html-form/javascript-form-validation.phtml[
^] but you must remember to still do validation on the server as well!