Share:

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

Popular posts from this blog

Get Color From Pixel C# WPF | Saatody | Amit Padhiyar

Basic Audio Operations With MP3 And Wave Files Using NAudio C#

Create Drag And Drop Operation Between DevExpress GridControl And Custom WPF UI | Saatody | Amit Padhiyar