C C# Learner Feb 14, 2004 #2 OC said: Is there a simple way to do this? Click to expand... Here is a simple way to prevent characters that aren't spaces or digits from being entered: private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { e.Handled = IsInvalidInput(e.KeyChar); } private static bool IsInvalidInput(char c) { return (c < '0' || c > '9') && c != ' '; } HTH
OC said: Is there a simple way to do this? Click to expand... Here is a simple way to prevent characters that aren't spaces or digits from being entered: private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { e.Handled = IsInvalidInput(e.KeyChar); } private static bool IsInvalidInput(char c) { return (c < '0' || c > '9') && c != ' '; } HTH