---
title: "How do I make a textbox that only accepts numbers?"  
description: "How do I make a textbox that only accepts numbers?"  
author: "Anonymous User"  
published: 2013-11-13  
updated: 2013-11-13  
canonical: https://www.mindstick.com/forum/1720/how-do-i-make-a-textbox-that-only-accepts-numbers  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How do I make a textbox that only accepts numbers?

I have a [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) in a [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) [windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) [form application](https://www.mindstick.com/interview/23108/how-to-create-form-application-using-dot-net) and i want the textbox only [accept](https://yourviews.mindstick.com/view/81278/we-have-to-accept-that-roger-federer-is-the-richest-one) the number. How to make a textbox accept only numbers?

## Replies

### Reply by Anonymous User

Hi John,\
You can try this:

```
private void textBox1_KeyPress(object sender,
KeyPressEventArgs e)    {        e.Handled =
!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);    }
```

Hope this will solve your problem.


---

Original Source: https://www.mindstick.com/forum/1720/how-do-i-make-a-textbox-that-only-accepts-numbers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
