only numbers in textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
how can i do this:
i have textbox, but i want that only numbers is possible to write in this
text box.

Thanks Lubos
 
attach handler to Validating event. Use regular expression to validate
textbox content. Cancel the event if the content does not match "only
numbers"
pseudo code written here:

private void TextBox1_Validating(object sender, CancelEventArgs e)
{
TextBox tb = (TextBox)sender;
e.Cancel = !Regex.IsMatch(tb.Text, "[0-9]*");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top