I'm new in C# and I would like to know how I can make a textbox that only accepts numbers. So if you type a decimal number it would be no problem but when you type something else then "0,1,2,3,4,5,6,7,8,9 or ," I would like to have it deleted in the textbox. I thought it is possible with KeyDown or TextChanged.
This is what I've tried already:
private void txt2011_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch("^[0-9]", txt2011.Text))
{
txt2011.Text = "0";
}
}
Thanks in advance