Use keypress to decide if a single letter is even valid for the type of
field.
In keypress...
if e.KeyChar == ...anything but 0-9 or period ...
e.Handled = true; //Set Handled to true to cancel the KeyPress event.
You could also check if the current text already contains a period, and if
so do not allow another. Then it is all handled in the KeyPress, and
regular expressions are not needed. This is only sufficient for a simple
number containing all digits and a single period. It also does not enforce
minimum or maximum numbers, therefore does not prevent the user from
entering a value outside of the range of the property it is meant to edit.
To validate a more complex number (contains fractions, or scientific
notation) using a regular expression you should use the TextChanged or Leave
event instead.
Michael Lang, MCSD