---
title: "Numeric Textbox"  
description: "Numeric Textbox"  
author: "Anonymous User"  
published: 2010-10-04  
updated: 2010-10-05  
canonical: https://www.mindstick.com/forum/17/numeric-textbox  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Numeric Textbox

Hello everyone , I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to create my [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) as a numeric [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) box which can take only numeric values.\
Please provide me any [sample](https://www.mindstick.com/news/2174/mars-mission-by-nasa-prepares-for-tests) or code.\
\
Thanks\
Chris\
\

## Replies

### Reply by Uttam Misra

Check this article Chris..\
\
http://www.mindstick.com/Articles/6e3c047c-17aa-4ea2-b390-a8b756404f09/\
\
\

```
 private voidtextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {            if (char.IsDigit(e.KeyChar)== false && e.KeyChar != '.' && e.KeyChar!='\b')//checking whether pressed key is number, decimal orbackspace.//If false then we will set Handled variable ofKeyPressEventArgs to true.//By doing this system will get a message that character of keypressed//is executed and hence aplpa numeric character will not bedisplayed//except decimal.                 e.Handled=true;            elseif (e.KeyChar == '.')                if(textBox1.Text.Contains('.'))                    e.Handled=true;           //checking whether decimal key is pressed or not, if truethen checking//whether decimal is already present or not, as we can haveonly//one decimal point in a text box.        }
```

\


---

Original Source: https://www.mindstick.com/forum/17/numeric-textbox

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
