Number Validation In TextBox WPF | C# | Amit Padhiyar | Saatody
I will create number validation in TextBox. This algorithm only allow numbers while user press any key.
TB.PreviewTextInput += (sender, e) =>
{
if (e.Text != "0" && e.Text != "1" && e.Text != "2" && e.Text != "3" && e.Text != "4" && e.Text != "5" && e.Text != "6" && e.Text != "7" && e.Text != "8" && e.Text != "9")
{
e.Handled = true;
}
};
Here is little demo on PreviewTextInput. I am researching on validations for TextBox. In future, I will create more detail about it.
Comments
Post a Comment