Make Textbox Number Only – WPF

Coding :

private void txt_PreviewTextInput(object sender, TextCompositionEventArgs e)
e.Handled = !ValidNumeric(e.Text);
bool ValidNumeric(string str)
bool ret = true;
int l = str.Length;
for (int i = 0; i < l; i++)
char ch = str[i];
ret &= Char.IsDigit(ch);
return ret;

Thanks dedjo

One thought on “Make Textbox Number Only – WPF

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>